Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Porting async implementation and adding TPL overrides for SslStream Read/WriteAsync #5541

Merged
merged 1 commit into from
Jan 22, 2016

Conversation

CIPop
Copy link

@CIPop CIPop commented Jan 20, 2016

  • Porting APM functionality for SslStream's InnerStream
  • Adding TPL wrappers
  • Adding the test proposed by @xanather

Fixes #5077

@stephentoub @davidsh @bartonjs @vijaykota PTAL

/cc @xanather, @benaadams @leecow

After review, I'll follow the internal process for RC2.

@CIPop
Copy link
Author

CIPop commented Jan 20, 2016

@benaadams If you have some time, it would be interesting to check if this fixes your issue while we wait for the PR review.

@benaadams
Copy link
Member

@CIPop can I use as is (e.g. I don't need the other Stream changes in this area) - will give it a go.

@CIPop
Copy link
Author

CIPop commented Jan 20, 2016

@CIPop can I use as is (e.g. I don't need the other Stream changes in this area) - will give it a go.

@benaadams If your code is using a true async stream (e.g. NetworkStream), I don't think you need the Stream enhancements for this to unblock you.

@benaadams
Copy link
Member

@CIPop its pure async; with the sync being simulated - which is why it interacted quite badly with the previous Stream's async overlay over the sync methods - ended up ticking all the "don't do" boxes of async rather than just the one 😁 e.g. it was sync over async and async over sync at the same time.

public async void SslStream_SendReceiveOverNetworkStream_Ok()
{
X509Certificate2 serverCertificate = TestConfiguration.GetServerCertificate();
TcpListener listener = new TcpListener(IPAddress.Any, 4567);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should change the port from a fixed '4567' to a dynamic port, i.e. '0'. Otherwise, if a single CI machine is running multiple instances of PR validation, this port might be busy running another test.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I've missed that when I was adapting the test for CI.

@benaadams
Copy link
Member

@CIPop I'm having trouble building it - though I think its a general corefx thing, so will start from scratch.

As an aside the CI tests can't compile e.g.

Error   CS1061  '_SslStream' does not contain a definition for 'BeginRead' and no extension 
method 'BeginRead' accepting a first argument of type '_SslStream' could be found (are you missing a using directive or an assembly reference?) 
System.Net.Security.Unit.Tests  I:\Work\GitHub\corefx\src\System.Net.Security\src\System\Net\SecureProtocols\SslStream.cs   446 

@CIPop
Copy link
Author

CIPop commented Jan 20, 2016

CI tests can't compile

Thanks @benaadams. Addressed that and will update the PR shortly. (The UT Fakes needed updated.)

@benaadams
Copy link
Member

@CIPop I can't build, I think I might be between tools; though it starts with this

I:\corefx>build.cmd
Building Native Libraries...
'&' is not recognized as an internal or external command,
operable program or batch file.
'I:\corefx\src\Native\Windows\probe-win.ps1 is not digitally signed. You cannot run this script on the current system. ' is not recognized as an internal or external command,
operable program or batch file.
'For' is not recognized as an internal or external command,
operable program or batch file.
'http:' is not recognized as an internal or external command,
operable program or batch file.
The system cannot find the path specified.
'+   ~~~~~~~~~~~~~~~' is not recognized as an internal or external command,
operable program or batch file.
The filename, directory name, or volume label syntax is incorrect.
The filename, directory name, or volume label syntax is incorrect.
'""' is not recognized as an internal or external command,
operable program or batch file.
Native component build failed see nativebuild.log for more details.
  Restoring all packages...

It does build some stuff though. If you could put the dll and pdb somewhere I could give it a go.

private static AsyncProtocolCallback _resumeAsyncWriteCallback = new AsyncProtocolCallback(ResumeAsyncWriteCallback);
private static AsyncProtocolCallback _resumeAsyncReadCallback = new AsyncProtocolCallback(ResumeAsyncReadCallback);
private static AsyncProtocolCallback _readHeaderCallback = new AsyncProtocolCallback(ReadHeaderCallback);
private static AsyncProtocolCallback _readFrameCallback = new AsyncProtocolCallback(ReadFrameCallback);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: These could all be readonly. They should also have an s_ prefix.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Fixed.

@stephentoub
Copy link
Member

LGTM

@stephentoub
Copy link
Member

The two Windows_NT failures are:

14:20:38      System.Net.Security.Tests.SslStreamStreamToStreamTest.SslStream_StreamToStream_Successive_ClientWrite_Sync_Success [FAIL]
14:20:38         Handshake completed.
14:20:38         Expected: True
14:20:38         Actual:   False
14:20:38         Stack Trace:
14:20:38            d:\j\workspace\dotnet_corefx\windows_nt_debug_prtest\src\System.Net.Security\tests\FunctionalTests\SslStreamStreamToStreamTest.cs(76,0): at System.Net.Security.Tests.SslStreamStreamToStreamTest.SslStream_StreamToStream_Successive_ClientWrite_Sync_Success()
14:20:38      System.Net.Security.Tests.ClientAsyncAuthenticateTest.ClientAsyncAuthenticate_ServerNoEncryption_NoConnect [FAIL]
14:20:38         Assert.Throws() Failure
14:20:38         Expected: typeof(System.IO.IOException)
14:20:38         Actual:   typeof(Xunit.Sdk.TrueException): Timed Out
14:20:38         Expected: True
14:20:38         Actual:   False
14:20:38         Stack Trace:
14:20:38            d:\j\workspace\dotnet_corefx\windows_nt_debug_prtest\src\System.Net.Security\tests\FunctionalTests\ClientAsyncAuthenticateTest.cs(172,0): at System.Net.Security.Tests.ClientAsyncAuthenticateTest.<ClientAsyncSslHelper>d__18.MoveNext()
14:20:38            --- End of stack trace from previous location where exception was thrown ---
14:20:38               at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
14:20:38               at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

@CIPop
Copy link
Author

CIPop commented Jan 22, 2016

@stephentoub

The two Windows_NT failures are

Since they are intermittent, I believe these are #4467. I found a few issues with both the test patterns and the Mock infra.

@CIPop
Copy link
Author

CIPop commented Jan 22, 2016

I can't build, I think I might be between tools; though it starts with this

@benaadams I don't see these errors but I think you're using PoshGit. Try to open a cmd command prompt instead.

…ppers and a simple test proposed by the community.
@davidsh
Copy link
Contributor

davidsh commented Jan 22, 2016

LGTM

CIPop added a commit that referenced this pull request Jan 22, 2016
Porting async implementation and adding TPL overrides for SslStream Read/WriteAsync
@CIPop CIPop merged commit fac18d8 into dotnet:master Jan 22, 2016
@CIPop CIPop deleted the snsrw branch January 22, 2016 18:35
@CIPop
Copy link
Author

CIPop commented Jan 22, 2016

Thanks for the review!

@benaadams
Copy link
Member

@CIPop still having a lock up post this fix; debugging into it (need to determine cause using v4.0.0-rc2-23722)

@benaadams
Copy link
Member

@CIPop still seem to be dropping into a System.IO.Stream Sync read in BeginReadInternal when running on framework net451 framework
SyncBlock

@benaadams
Copy link
Member

Call stack

callstack

@CIPop
Copy link
Author

CIPop commented Jan 26, 2016

@benaadams This fix is only for corefx. net451 would use .Net Desktop implementations. Can you repro this on CoreFX?

@benaadams
Copy link
Member

Trying

@benaadams
Copy link
Member

Yes; on 32-bit DNXCore 5.0 though trying to workout how to get some debug info to find out what's going on; might be a different cause - will keep you posted.

The current clr/coreclr I'm using is:

#if DOTNET5_4
     return WriteAsyncAwaited(buffer, cancellationToken);
#else
     Write(buffer);
     return TaskUtilities.CompletedTask;
#endif

@CIPop
Copy link
Author

CIPop commented Jan 27, 2016

@benaadams For visibility and tracking purposes it would be best to open a different issue and add the details there. It appears that the requirements are different for your issue to repro compared to #5077.

If creating a small repro project isn't practical (and for your current debugging), try collecting ETW logs: https://github.com/dotnet/corefx/blob/master/Documentation/debugging/windows-instructions.md

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

Successfully merging this pull request may close these issues.

6 participants