-
Notifications
You must be signed in to change notification settings - Fork 725
Error handling for GetCapabilitiesAsync connection issues #8614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -88,38 +88,49 @@ await rpc.InvokeWithCancellationAsync( | |
|
|
||
| public async Task ConnectAsync(Process process, string socketPath, CancellationToken cancellationToken) | ||
| { | ||
| using var activity = _activitySource.StartActivity(); | ||
|
|
||
| _process = process; | ||
|
|
||
| if (_rpcTaskCompletionSource.Task.IsCompleted) | ||
| try | ||
| { | ||
| throw new InvalidOperationException("Already connected to AppHost backchannel."); | ||
| using var activity = _activitySource.StartActivity(); | ||
|
|
||
| _process = process; | ||
|
|
||
| if (_rpcTaskCompletionSource.Task.IsCompleted) | ||
| { | ||
| throw new InvalidOperationException("Already connected to AppHost backchannel."); | ||
| } | ||
|
|
||
| logger.LogDebug("Connecting to AppHost backchannel at {SocketPath}", socketPath); | ||
| var socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified); | ||
| var endpoint = new UnixDomainSocketEndPoint(socketPath); | ||
| await socket.ConnectAsync(endpoint, cancellationToken); | ||
| logger.LogDebug("Connected to AppHost backchannel at {SocketPath}", socketPath); | ||
|
|
||
| var stream = new NetworkStream(socket, true); | ||
| var rpc = JsonRpc.Attach(stream, target); | ||
|
|
||
| var capabilities = await rpc.InvokeWithCancellationAsync<string[]>( | ||
| "GetCapabilitiesAsync", | ||
| Array.Empty<object>(), | ||
| cancellationToken); | ||
|
|
||
| if (!capabilities.Any(s => s == "baseline.v0")) | ||
| { | ||
| throw new AppHostIncompatibleException( | ||
| $"AppHost is incompatible with the CLI. The AppHost must be updated to a version that supports the baseline.v0 capability.", | ||
| "baseline.v0" | ||
| ); | ||
| } | ||
|
|
||
| _rpcTaskCompletionSource.SetResult(rpc); | ||
| } | ||
|
|
||
| logger.LogDebug("Connecting to AppHost backchannel at {SocketPath}", socketPath); | ||
| var socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified); | ||
| var endpoint = new UnixDomainSocketEndPoint(socketPath); | ||
| await socket.ConnectAsync(endpoint, cancellationToken); | ||
| logger.LogDebug("Connected to AppHost backchannel at {SocketPath}", socketPath); | ||
|
|
||
| var stream = new NetworkStream(socket, true); | ||
| var rpc = JsonRpc.Attach(stream, target); | ||
|
|
||
| var capabilities = await rpc.InvokeWithCancellationAsync<string[]>( | ||
| "GetCapabilitiesAsync", | ||
| Array.Empty<object>(), | ||
| cancellationToken); | ||
|
|
||
| if (!capabilities.Any(s => s == "baseline.v0")) | ||
| catch (RemoteMethodNotFoundException ex) | ||
| { | ||
| logger.LogError(ex, "Failed to connect to AppHost backchannel. The AppHost must be updated to a version that supports the baseline.v0 capability."); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit, wouldn't this only happen if GetCapabilitiesAsync wasn't defined, which it will be in every version.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct :) But we are being defensive because this caught us out. |
||
| throw new AppHostIncompatibleException( | ||
| $"AppHost is incompatible with the CLI. The AppHost must be updated to a version that supports the baseline.v0 capability.", | ||
| "baseline.v0" | ||
| ); | ||
| } | ||
|
|
||
| _rpcTaskCompletionSource.SetResult(rpc); | ||
| } | ||
|
|
||
| public async Task<string[]> GetPublishersAsync(CancellationToken cancellationToken) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.