Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions src/Dotnet.Watch/HotReloadAgent.Host/Listener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public Task Listen(CancellationToken cancellationToken)
{
try
{
await ReceiveAndApplyUpdatesAsync(initialUpdates: false, cancellationToken);
await ReceiveAndApplyUpdatesAsync(initialUpdates: false, cancellationToken).ConfigureAwait(false);
}
catch (Exception e) when (e is not OperationCanceledException)
{
Expand All @@ -72,35 +72,35 @@ private async Task InitializeAsync(CancellationToken cancellationToken)
{
agent.Reporter.Report("Writing capabilities: " + agent.Capabilities, AgentMessageSeverity.Verbose);

await transport.SendAsync(new ClientInitializationResponse(agent.Capabilities), cancellationToken);
await transport.SendAsync(new ClientInitializationResponse(agent.Capabilities), cancellationToken).ConfigureAwait(false);

// Apply updates made before this process was launched to avoid executing unupdated versions of the affected modules.

// We should only receive ManagedCodeUpdate when when the debugger isn't attached,
// otherwise the initialization should send InitialUpdatesCompleted immediately.
// The debugger itself applies these updates when launching process with the debugger attached.
await ReceiveAndApplyUpdatesAsync(initialUpdates: true, cancellationToken);
await ReceiveAndApplyUpdatesAsync(initialUpdates: true, cancellationToken).ConfigureAwait(false);
}

private async Task ReceiveAndApplyUpdatesAsync(bool initialUpdates, CancellationToken cancellationToken)
{
while (!cancellationToken.IsCancellationRequested)
{
using var request = await transport.ReceiveAsync(cancellationToken);
using var request = await transport.ReceiveAsync(cancellationToken).ConfigureAwait(false);
if (request.Stream == null)
{
break;
}

var payloadType = (RequestType)await request.Stream.ReadByteAsync(cancellationToken);
var payloadType = (RequestType)await request.Stream.ReadByteAsync(cancellationToken).ConfigureAwait(false);
switch (payloadType)
{
case RequestType.ManagedCodeUpdate:
await ReadAndApplyManagedCodeUpdateAsync(request.Stream, cancellationToken);
await ReadAndApplyManagedCodeUpdateAsync(request.Stream, cancellationToken).ConfigureAwait(false);
break;

case RequestType.StaticAssetUpdate:
await ReadAndApplyStaticAssetUpdateAsync(request.Stream, cancellationToken);
await ReadAndApplyStaticAssetUpdateAsync(request.Stream, cancellationToken).ConfigureAwait(false);
break;

case RequestType.InitialUpdatesCompleted when initialUpdates:
Expand All @@ -115,7 +115,7 @@ private async Task ReceiveAndApplyUpdatesAsync(bool initialUpdates, Cancellation

private async ValueTask ReadAndApplyManagedCodeUpdateAsync(Stream stream, CancellationToken cancellationToken)
{
var request = await ManagedCodeUpdateRequest.ReadAsync(stream, cancellationToken);
var request = await ManagedCodeUpdateRequest.ReadAsync(stream, cancellationToken).ConfigureAwait(false);

bool success;
try
Expand All @@ -132,12 +132,12 @@ private async ValueTask ReadAndApplyManagedCodeUpdateAsync(Stream stream, Cancel

var logEntries = agent.Reporter.GetAndClearLogEntries(request.ResponseLoggingLevel);

await SendResponseAsync(new UpdateResponse(logEntries, success), cancellationToken);
await SendResponseAsync(new UpdateResponse(logEntries, success), cancellationToken).ConfigureAwait(false);
}

private async ValueTask ReadAndApplyStaticAssetUpdateAsync(Stream stream, CancellationToken cancellationToken)
{
var request = await StaticAssetUpdateRequest.ReadAsync(stream, cancellationToken);
var request = await StaticAssetUpdateRequest.ReadAsync(stream, cancellationToken).ConfigureAwait(false);

try
{
Expand All @@ -153,16 +153,16 @@ private async ValueTask ReadAndApplyStaticAssetUpdateAsync(Stream stream, Cancel
// Updating static asset only invokes ContentUpdate metadata update handlers.
// Failures of these handlers are reported to the log and ignored.
// Therefore, this request always succeeds.
await SendResponseAsync(new UpdateResponse(logEntries, success: true), cancellationToken);
await SendResponseAsync(new UpdateResponse(logEntries, success: true), cancellationToken).ConfigureAwait(false);
}

internal async ValueTask SendResponseAsync<T>(T response, CancellationToken cancellationToken)
where T : IResponse
{
try
{
await _messageToClientLock.WaitAsync(cancellationToken);
await transport.SendAsync(response, cancellationToken);
await _messageToClientLock.WaitAsync(cancellationToken).ConfigureAwait(false);
await transport.SendAsync(response, cancellationToken).ConfigureAwait(false);
}
finally
{
Expand Down
10 changes: 5 additions & 5 deletions src/Dotnet.Watch/HotReloadAgent.Host/WebSocketTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public override async ValueTask SendAsync(IResponse response, CancellationToken
}

Log($"Connecting to {serverUrl}...");
await _webSocket.ConnectAsync(new Uri(serverUrl), connectCts.Token);
await _webSocket.ConnectAsync(new Uri(serverUrl), connectCts.Token).ConfigureAwait(false);
Log("Connected.");
}
catch (OperationCanceledException) when (!cancellationToken.IsCancellationRequested)
Expand All @@ -71,8 +71,8 @@ public override async ValueTask SendAsync(IResponse response, CancellationToken
_sendBuffer ??= new MemoryStream();
_sendBuffer.SetLength(0);

await _sendBuffer.WriteAsync((byte)response.Type, cancellationToken);
await response.WriteAsync(_sendBuffer, cancellationToken);
await _sendBuffer.WriteAsync((byte)response.Type, cancellationToken).ConfigureAwait(false);
await response.WriteAsync(_sendBuffer, cancellationToken).ConfigureAwait(false);

Log($"Sending {response.Type} ({_sendBuffer.Length} bytes)");

Expand All @@ -81,7 +81,7 @@ await _webSocket.SendAsync(
new ArraySegment<byte>(_sendBuffer.GetBuffer(), 0, (int)_sendBuffer.Length),
WebSocketMessageType.Binary,
endOfMessage: true,
cancellationToken);
cancellationToken).ConfigureAwait(false);
}

public override async ValueTask<RequestStream> ReceiveAsync(CancellationToken cancellationToken)
Expand All @@ -101,7 +101,7 @@ public override async ValueTask<RequestStream> ReceiveAsync(CancellationToken ca
WebSocketReceiveResult result;
do
{
result = await _webSocket.ReceiveAsync(new ArraySegment<byte>(buffer), cancellationToken);
result = await _webSocket.ReceiveAsync(new ArraySegment<byte>(buffer), cancellationToken).ConfigureAwait(false);

if (result.MessageType == WebSocketMessageType.Close)
{
Expand Down
Loading