Skip to content

[Named pipes] Disconnect + delayed client read test cases #46166

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

Merged

Conversation

simonferquel
Copy link
Contributor

@simonferquel simonferquel commented Jan 19, 2023

[Named pipes] Disconnect + delayed client read test cases

Description

Adds tests in Named Pipes support to check that the client won't miss last bytes written to the pipe, if NamedPipeConnection::Transport.Output.Complete() or NamedPipeConnection::Transport.Output.DisposeAsync() is called before the last client-side Read happens.

Luckily, with current implementation, PipeOptions.WriteThrough make sure the Read happens before exiting the SendLoop. The introduced tests here are there to make sure this does not regress.

contributes to #14207

… is disposed earlier than the next client read happens

Signed-off-by: Simon Ferquel <[email protected]>
@ghost ghost added area-runtime community-contribution Indicates that the PR has been added by a community member labels Jan 19, 2023
@ghost
Copy link

ghost commented Jan 19, 2023

Thanks for your PR, @simonferquel. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@JamesNK JamesNK self-assigned this Jan 20, 2023
@simonferquel
Copy link
Contributor Author

The test actually revealed an error case on Linux it seems:

Microsoft.AspNetCore.Server.Kestrel.Transport.NamedPipes.Tests.NamedPipeConnectionListenerTests.DisposeAsync_BeforeClientHasReadLastBytes_DontLooseData [FAIL]
2023-01-19T11:53:02.4213048Z [xUnit.net 00:00:01.78]       Assert.False() Failure
2023-01-19T11:53:02.4274415Z [xUnit.net 00:00:01.78]       Expected: False
2023-01-19T11:53:02.4338655Z [xUnit.net 00:00:01.78]       Actual:   True
2023-01-19T11:53:02.4380630Z [xUnit.net 00:00:01.78]       Stack Trace:
2023-01-19T11:53:02.4462600Z [xUnit.net 00:00:01.78]         /_/src/Servers/Kestrel/Transport.NamedPipes/test/NamedPipeConnectionListenerTests.cs(212,0): at Microsoft.AspNetCore.Server.Kestrel.Transport.NamedPipes.Tests.NamedPipeConnectionListenerTests.DisposeAsync_BeforeClientHasReadLastBytes_DontLooseData()
2023-01-19T11:53:02.4505907Z [xUnit.net 00:00:01.78]         /_/src/Servers/Kestrel/Transport.NamedPipes/test/NamedPipeConnectionListenerTests.cs(216,0): at Microsoft.AspNetCore.Server.Kestrel.Transport.NamedPipes.Tests.NamedPipeConnectionListenerTests.DisposeAsync_BeforeClientHasReadLastBytes_DontLooseData()
2023-01-19T11:53:02.4545856Z [xUnit.net 00:00:01.78]         --- End of stack trace from previous location ---
2023-01-19T11:53:02.4581041Z [xUnit.net 00:00:01.78]       Output:
2023-01-19T11:53:02.4612173Z [xUnit.net 00:00:01.78]         | [0.002s] TestLifetime Information: Starting test DisposeAsync_BeforeClientHasReadLastBytes_DontLooseData at 2023-01-19T11:53:01
2023-01-19T11:53:02.4650853Z [xUnit.net 00:00:01.78]         | [0.028s] Microsoft.AspNetCore.Server.Kestrel.Transport.NamedPipes Debug: Connection id "0HMNQ2ERNO9FP" accepted.
2023-01-19T11:53:02.4685800Z [xUnit.net 00:00:01.78]         | [0.043s] Microsoft.AspNetCore.Server.Kestrel.Transport.NamedPipes Debug: Connection id "0HMNQ2ERNO9FP" disconnecting stream because: "The Socket transport's send loop completed gracefully."
2023-01-19T11:53:02.4716009Z [xUnit.net 00:00:01.78]         | [0.132s] Microsoft.AspNetCore.Server.Kestrel.Transport.NamedPipes Debug: Connection id "0HMNQ2ERNO9FP" unexpected error.
2023-01-19T11:53:02.4746880Z [xUnit.net 00:00:01.78]         | System.IO.IOException: Operation canceled
2023-01-19T11:53:02.4775584Z [xUnit.net 00:00:01.78]         |  ---> System.Net.Sockets.SocketException (125): Operation canceled
2023-01-19T11:53:02.4807519Z [xUnit.net 00:00:01.78]         |    at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
2023-01-19T11:53:02.4837244Z [xUnit.net 00:00:01.78]         |    at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource<System.Int32>.GetResult(Int16 token)
2023-01-19T11:53:02.4865901Z [xUnit.net 00:00:01.78]         |    at System.IO.Pipes.PipeStream.ReadAsyncCore(Memory`1 destination, CancellationToken cancellationToken)
2023-01-19T11:53:02.4874343Z [xUnit.net 00:00:01.78]         |    --- End of inner exception stack trace ---
2023-01-19T11:53:02.4880386Z [xUnit.net 00:00:01.78]         |    at System.IO.Pipes.PipeStream.ReadAsyncCore(Memory`1 destination, CancellationToken cancellationToken)
2023-01-19T11:53:02.4886407Z [xUnit.net 00:00:01.78]         |    at Microsoft.AspNetCore.Server.Kestrel.Transport.NamedPipes.Internal.NamedPipeConnection.DoReceiveAsync() in /_/src/Servers/Kestrel/Transport.NamedPipes/src/Internal/NamedPipeConnection.cs:line 83
2023-01-19T11:53:02.4892389Z [xUnit.net 00:00:01.78]         | [0.793s] Microsoft.AspNetCore.Server.Kestrel.Transport.NamedPipes Debug: Named pipe listener aborted.
2023-01-19T11:53:02.4898417Z [xUnit.net 00:00:01.78]         | System.OperationCanceledException: The operation was canceled.
2023-01-19T11:53:02.4904167Z [xUnit.net 00:00:01.78]         |    at System.Threading.CancellationToken.ThrowOperationCanceledException()
2023-01-19T11:53:02.4910562Z [xUnit.net 00:00:01.78]         |    at System.Threading.CancellationToken.ThrowIfCancellationRequested()
2023-01-19T11:53:02.4916842Z [xUnit.net 00:00:01.78]         |    at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
2023-01-19T11:53:02.4922940Z [xUnit.net 00:00:01.78]         |    at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource<System.Net.Sockets.Socket>.GetResult(Int16 token)
2023-01-19T11:53:02.4929086Z [xUnit.net 00:00:01.79]         |    at System.IO.Pipes.NamedPipeServerStream.<>c__DisplayClass25_0.<<WaitForConnectionAsync>g__WaitForConnectionAsyncCore|0>d.MoveNext()
2023-01-19T11:53:02.4935135Z [xUnit.net 00:00:01.79]         | --- End of stack trace from previous location ---
2023-01-19T11:53:02.4941159Z [xUnit.net 00:00:01.79]         |    at Microsoft.AspNetCore.Server.Kestrel.Transport.NamedPipes.Internal.NamedPipeConnectionListener.StartAsync(NamedPipeServerStream nextStream) in /_/src/Servers/Kestrel/Transport.NamedPipes/src/Internal/NamedPipeConnectionListener.cs:line 79
2023-01-19T11:53:02.4947476Z [xUnit.net 00:00:01.79]         | [0.815s] Microsoft.AspNetCore.Server.Kestrel.Transport.NamedPipes.Tests.NamedPipeConnectionListenerTests Error: Test threw an exception.
2023-01-19T11:53:02.4953219Z [xUnit.net 00:00:01.79]         | Xunit.Sdk.FalseException: Assert.False() Failure
2023-01-19T11:53:02.4959058Z [xUnit.net 00:00:01.79]         | Expected: False
2023-01-19T11:53:02.4965010Z [xUnit.net 00:00:01.79]         | Actual:   True
2023-01-19T11:53:02.4970695Z [xUnit.net 00:00:01.79]         |    at Xunit.Assert.False(Nullable`1 condition, String userMessage) in /_/src/xunit.assert/Asserts/BooleanAsserts.cs:line 73
2023-01-19T11:53:02.4976768Z [xUnit.net 00:00:01.79]         |    at Xunit.Assert.False(Boolean condition) in /_/src/xunit.assert/Asserts/BooleanAsserts.cs:line 28
2023-01-19T11:53:02.4983570Z [xUnit.net 00:00:01.79]         |    at Microsoft.AspNetCore.Server.Kestrel.Transport.NamedPipes.Tests.NamedPipeConnectionListenerTests.DisposeAsync_BeforeClientHasReadLastBytes_DontLooseData() in /_/src/Servers/Kestrel/Transport.NamedPipes/test/NamedPipeConnectionListenerTests.cs:line 212
2023-01-19T11:53:02.4989875Z [xUnit.net 00:00:01.79]         |    at Microsoft.AspNetCore.Server.Kestrel.Transport.NamedPipes.Tests.NamedPipeConnectionListenerTests.DisposeAsync_BeforeClientHasReadLastBytes_DontLooseData() in /_/src/Servers/Kestrel/Transport.NamedPipes/test/NamedPipeConnectionListenerTests.cs:line 216
2023-01-19T11:53:02.4996076Z [xUnit.net 00:00:01.79]         |    at Xunit.Sdk.TestInvoker`1.<>c__DisplayClass48_0.<<InvokeTestMethodAsync>b__1>d.MoveNext() in /_/src/xunit.execution/Sdk/Frameworks/Runners/TestInvoker.cs:line 264
2023-01-19T11:53:02.5002144Z [xUnit.net 00:00:01.79]         | --- End of stack trace from previous location ---
2023-01-19T11:53:02.5008254Z [xUnit.net 00:00:01.79]         |    at Xunit.Sdk.ExecutionTimer.AggregateAsync(Func`1 asyncAction) in /_/src/xunit.execution/Sdk/Frameworks/ExecutionTimer.cs:line 48
2023-01-19T11:53:02.5014167Z [xUnit.net 00:00:01.79]         |    at Xunit.Sdk.ExceptionAggregator.RunAsync(Func`1 code) in /_/src/xunit.core/Sdk/ExceptionAggregator.cs:line 90
2023-01-19T11:53:02.5122547Z [xUnit.net 00:00:01.79]         | [0.817s] TestLifetime Information: Finished test DisposeAsync_BeforeClientHasReadLastBytes_DontLooseData in 0.8151272s

On Linux it seems the write call does complete immediately, and the exception raised on the read task is not catched (it is a bit surprising to see a Cancelled exception wrapped in an IOException). I'll make a fix for that in that PR.

@simonferquel
Copy link
Contributor Author

This actually seem to be a test error, with an assertion failing because on Linux, from the server side the Write call is not blocking, but the read from the client side actually succeeds.

@JamesNK
Copy link
Member

JamesNK commented Jan 24, 2023

I excluded the tests on Linux and macOS.

I think we'll disable using the named pipes transport outside of Windows: #46231

@simonferquel
Copy link
Contributor Author

Makes sense yes

@JamesNK JamesNK requested a review from amcasey January 24, 2023 13:17
@JamesNK JamesNK merged commit bb2d9ac into dotnet:main Jan 31, 2023
@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants