Skip to content
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

Fix mis-reported cancellation of message transmission #492

Merged
merged 2 commits into from
Jul 16, 2020

Conversation

AArnott
Copy link
Member

@AArnott AArnott commented Jul 15, 2020

When a message is written to the output stream but not flushed, and then cancellation is requested, although the flush was canceled, the message was eventually going to be sent even though the client was no longer tracking it. This led to an unexpected response from the server to eventually be received and in v2.5, JsonRpc terminates the connection when the server sends an unexpected response to a request it doesn't remember sending.

The fix is to stop honoring the CancellationToken after the message has been written. We still honor the disposal token during flush so as to not hold up shutdown, but after a message is written, we always wait for flush to complete if we're still running.

Fixes #489

AArnott added 2 commits July 15, 2020 14:41
When a message is written to the output stream but not flushed, and then cancellation is requested, although the flush was canceled, the message was eventually going to be sent even though the client was no longer tracking it. This led to an unexpected response from the server to eventually be received and in v2.5, `JsonRpc` terminates the connection when the server sends an unexpected response to a request it doesn't remember sending.

The fix is to stop honoring the `CancellationToken` after the message has been written. We still honor the *disposal* token during flush so as to not hold up shutdown, but after a message is written, we always wait for flush to complete if we're still running.

Fixes microsoft#489
@AArnott AArnott added this to the v2.6 milestone Jul 15, 2020
@AArnott AArnott self-assigned this Jul 15, 2020
@codecov-commenter
Copy link

codecov-commenter commented Jul 15, 2020

Codecov Report

Merging #492 into master will decrease coverage by 0.42%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #492      +/-   ##
==========================================
- Coverage   90.64%   90.22%   -0.43%     
==========================================
  Files          50       50              
  Lines        3838     3815      -23     
==========================================
- Hits         3479     3442      -37     
- Misses        359      373      +14     
Impacted Files Coverage Δ
src/StreamJsonRpc/MessageHandlerBase.cs 98.78% <100.00%> (+0.04%) ⬆️
src/StreamJsonRpc/Exceptions/LocalRpcException.cs 62.50% <0.00%> (-12.50%) ⬇️
src/StreamJsonRpc/LengthHeaderMessageHandler.cs 97.22% <0.00%> (-2.78%) ⬇️
...rc/StreamJsonRpc/NewLineDelimitedMessageHandler.cs 86.53% <0.00%> (-1.93%) ⬇️
...pc/Reflection/MessageFormatterEnumerableTracker.cs 94.69% <0.00%> (-1.04%) ⬇️
src/StreamJsonRpc/JsonRpc.cs 92.29% <0.00%> (-0.79%) ⬇️
src/StreamJsonRpc/Reflection/MethodSignature.cs 76.74% <0.00%> (-0.53%) ⬇️
src/StreamJsonRpc/MessagePackFormatter.cs 92.83% <0.00%> (-0.52%) ⬇️
src/StreamJsonRpc/HeaderDelimitedMessageHandler.cs 85.63% <0.00%> (-0.42%) ⬇️
src/StreamJsonRpc/JsonRpcEventSource.cs 6.97% <0.00%> (-0.35%) ⬇️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 813fd29...add0893. Read the comment docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Race condition in InvokeWithCancellationAsync
3 participants