-
Notifications
You must be signed in to change notification settings - Fork 448
Give Client a chance to receive Close Frame from Server #730
Conversation
@@ -62,7 +62,7 @@ public WebSocketsTransportTests(ServerFixture<Startup> serverFixture, ITestOutpu | |||
await webSocketsTransport.StartAsync(new Uri(_serverFixture.WebSocketsUrl + "/echo"), channelConnection, | |||
TransferMode.Binary, connectionId: string.Empty); | |||
connectionToTransport.Out.TryComplete(); | |||
await webSocketsTransport.Running.OrTimeout(); | |||
await webSocketsTransport.Running.OrTimeout(TimeSpan.FromSeconds(10)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a fan... can we add an option or something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you need to extend this timeout?
Also, this test failed on AppVeyor so it does not seem increasing this timeout helped.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The known flaky SSE test failed in AppVeyor. And the timeout is because we wait 5 seconds in WebSockets before canceling the ReceiveAsync
You can still exit the loop in two places if
|
@@ -198,7 +208,7 @@ public WebSocketsTransport(ILoggerFactory loggerFactory) | |||
finally | |||
{ | |||
_logger.SendStopped(_connectionId); | |||
_transportCts.Cancel(); | |||
TriggerCancel(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this needed? if you get here it means that receiveCts has been cancelled or there was an exception. I think we only need _transportCts.Cancel()
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scratch that - I did not expand and thought it was in the Receive loop.
} | ||
} | ||
catch (OperationCanceledException) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worth logging?
@@ -198,7 +208,7 @@ public WebSocketsTransport(ILoggerFactory loggerFactory) | |||
finally | |||
{ | |||
_logger.SendStopped(_connectionId); | |||
_transportCts.Cancel(); | |||
TriggerCancel(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scratch that - I did not expand and thought it was in the Receive loop.
🐑🇮🇹 |
Issue was
HttpConnection.DisposeAsync()
was being called and it would complete the Channel then calltransport.StopAsync()
, the Channel completion would trigger the transport send loop to exit and cancel the_transportCts
which would cause_webSocket.ReceiveAsync()
to exit so it can't receive the close frame. This would happen in parallel with us calling_webSocket.CloseOutputAsync
.Now we use a different CTS for the webSocket calls so we have a chance to send and receive a close frame before exiting.
#720