runtime icon indicating copy to clipboard operation
runtime copied to clipboard

Test failure: Manual_CertificateSentMatchesCertificateReceived_Success

Open stephentoub opened this issue 10 years ago • 43 comments

The test as currently written fails sporadically on Windows. If, however, GC.Collect(); GC.WaitForPendingFinalizers(); is added inside the loop here: https://github.com/dotnet/corefx/blob/483aa5a3012fe78ea001ece1b0404b18c0b90a29/src/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.ClientCertificates.cs#L117 the reuseClient==false test fails deterministically for me with the error "The client certificate credentials were not recognized". It appears something is getting finalized and preventing the same certificate instance from being used with subsequent HttpClientHandler instances.

stephentoub avatar Jun 20 '16 12:06 stephentoub

Failed on Ubuntu here: http://dotnet-ci.cloudapp.net/job/dotnet_corefx/job/master/job/ubuntu14.04_debug_prtest/2303/testReport/junit/System.Net.Http.Functional.Tests/HttpClientHandler_ClientCertificates_Test/Manual_CertificateSentMatchesCertificateReceived_Success_numberOfRequests__3__reuseClient__True_/

Stacktrace

MESSAGE:
System.Threading.Tasks.TaskCanceledException : A task was canceled.
+++++++++++++++++++
STACK TRACE:
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at System.Net.Http.Functional.Tests.HttpClientHandler_ClientCertificates_Test.<>c__DisplayClass5_0.<<Manual_CertificateSentMatchesCertificateReceived_Success>b__2>d.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at System.Net.Http.Functional.Tests.HttpClientHandler_ClientCertificates_Test.<>c__DisplayClass5_2.<<Manual_CertificateSentMatchesCertificateReceived_Success>b__4>d.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at System.Net.Test.Common.LoopbackServer.<>c__DisplayClass3_0.<CreateServerAsync>b__0(Task t) at System.Threading.Tasks.Task.Execute() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at System.Net.Http.Functional.Tests.HttpClientHandler_ClientCertificates_Test.<Manual_CertificateSentMatchesCertificateReceived_Success>d__5.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

mellinoe avatar Jun 23 '16 22:06 mellinoe

Failed on Ubuntu again:

http://dotnet-ci.cloudapp.net/job/dotnet_corefx/job/master/job/ubuntu14.04_debug_prtest/2465/testReport/junit/System.Net.Http.Functional.Tests/HttpClientHandler_ClientCertificates_Test/Manual_CertificateSentMatchesCertificateReceived_Success_numberOfRequests__3__reuseClient__True_/

mellinoe avatar Jun 30 '16 22:06 mellinoe

Failed on Ubuntu again

Thanks, but this is a different failure than the one highlighted. This is a timeout, whereas the other is some kind of data corruption due to finalization.

stephentoub avatar Jun 30 '16 22:06 stephentoub

Sorry about that, you're right. Looks like both of my links are for a different root cause (and different OS).

I filed dotnet/corefx#9785 for the Ubuntu issue.

mellinoe avatar Jun 30 '16 22:06 mellinoe

@stephentoub I have a theory about why this test is failing.

the reuseClient==false test fails deterministicly for me with the error "The client certificate credentials were not recognized". It appears something is getting finalized and preventing the same certificate instance from being used with subsequent HttpClientHandler instances.

The client certificate used in this test is a STATIC thing coming from here: https://github.com/dotnet/corefx/blob/master/src/Common/tests/System/Net/Configuration.Certificates.cs#L24

This client certificate is added to an instance of an X509Certificate2Collection object within a HttpClientHandler object. What are the dispose/finalization rules for X509Certificate2Collection? Does it dispose of things in the collection? If it does, this is why this is failing. The fix for this is to create instance copies of the client certificate instead of re-using a static object.

@bartonjs Can you comment on this?

cc: @CIPop

davidsh avatar Aug 27 '16 01:08 davidsh

I think the best solution is probably to change Configuration.Certificate.cs so that it returns a new instance of the certificates.

It's ok for the DATA to create a certificate (server or client) to be a static thing. But the X509Certificate2 object itself that is returned should be a new instance copy.

davidsh avatar Aug 27 '16 02:08 davidsh

@davidsh X509Certificate2Collection isn't inherently IDisposable; nothing would Dispose a cert unless you did it manually. That said, the X509Certificate tests do hold static data, and each test that wants the data clones it anew.

bartonjs avatar Aug 27 '16 04:08 bartonjs

Fails on build 20161204.02. So adding "test-run-core" https://mc.dot.net/#/product/netcore/master/source/official~2Fcorefx~2Fmaster~2F/type/test~2Ffunctional~2Fcli~2F/build/20161204.02/workItem/System.Net.Http.Functional.Tests/analysis/xunit/System.Net.Http.Functional.Tests.HttpClientHandler_ClientCertificates_Test~2FManual_CertificateSentMatchesCertificateReceived_Success(numberOfRequests:%203,%20reuseClient:%20True)

Unhandled Exception of Type System.Threading.Tasks.TaskCanceledException
Message :
System.Threading.Tasks.TaskCanceledException : A task was canceled.

Stack Trace :
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at System.Net.Http.Functional.Tests.HttpClientHandler_ClientCertificates_Test.<>c__DisplayClass5_0.<<Manual_CertificateSentMatchesCertificateReceived_Success>b__2>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at System.Net.Http.Functional.Tests.HttpClientHandler_ClientCertificates_Test.<>c__DisplayClass5_2.<<Manual_CertificateSentMatchesCertificateReceived_Success>b__4>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at System.Net.Test.Common.LoopbackServer.<>c__DisplayClass3_0.<CreateServerAsync>b__0(Task t)
   at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at System.Net.Http.Functional.Tests.HttpClientHandler_ClientCertificates_Test.<Manual_CertificateSentMatchesCertificateReceived_Success>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

jiangzeng avatar Dec 05 '16 01:12 jiangzeng

Fails on build 20161227.01, please check: https://mc.dot.net/#/product/netcore/master/source/official~2Fcorefx~2Fmaster~2F/type/test~2Ffunctional~2Fcli~2F/build/20161227.01/workItem/System.Net.Http.Functional.Tests/analysis/xunit/System.Net.Http.Functional.Tests.HttpClientHandler_ClientCertificates_Test~2FManual_CertificateSentMatchesCertificateReceived_Success(numberOfRequests:%203,%20reuseClient:%20True)

Message:

System.Threading.Tasks.TaskCanceledException : A task was canceled.

Stack Trace:

at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at System.Net.Http.Functional.Tests.HttpClientHandler_ClientCertificates_Test.<>c__DisplayClass5_0.<<Manual_CertificateSentMatchesCertificateReceived_Success>b__2>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at System.Net.Http.Functional.Tests.HttpClientHandler_ClientCertificates_Test.<>c__DisplayClass5_2.<<Manual_CertificateSentMatchesCertificateReceived_Success>b__4>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at System.Net.Test.Common.LoopbackServer.<>c__DisplayClass3_0.<CreateServerAsync>b__0(Task t)
   at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at System.Net.Http.Functional.Tests.HttpClientHandler_ClientCertificates_Test.<Manual_CertificateSentMatchesCertificateReceived_Success>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

KristinXie1 avatar Dec 28 '16 02:12 KristinXie1

Tracking all System.Net intermittently failing bugs with dotnet/corefx#14519.

CIPop avatar Dec 28 '16 19:12 CIPop

Reopening since it's being referenced by dotnet/corefx#16167

stephentoub avatar Feb 15 '17 00:02 stephentoub

I believe there are two issues with this test:

  1. A cert was reused after it was gc'd and caused errors like "The client certificate credentials were not recognized". This was fixed with the creation of the cert every time through the loop https://github.com/dotnet/corefx/issues/15777
  2. The test fails with "a task has been canceled" or "The server returned an invalid or unrecognized response". This has not been fixed yet.

steveharter avatar Feb 17 '17 19:02 steveharter

This is still active; may or may not be a test bug as the last attempt to fix resulted in occasional test hangs

steveharter avatar Mar 01 '17 23:03 steveharter

Flagging this as product bug, not test bug. Adding a Task.Delay(1) at the end of makeAndValidateRequest() appears to mask the issue and avoid the occasional exception. Perhaps there is a timing or race condition stemming from calling LoopbackServer.AcceptSocketAsync for each run (with the same server).

This can be repro'd on Windows by changing the

        [InlineData(6, false)]
        [InlineData(3, true)]

to

        [InlineData(600, false)]
        [InlineData(300, true)]

or similar large value. I've found that locally only a single run is should raise an exception, although two may be needed.

steveharter avatar Mar 20 '17 22:03 steveharter

@steveharter Do you still have a repro? (I couldn't repro with the above values - looks like this one is very tightly related to timings.)

CIPop avatar Apr 26 '17 01:04 CIPop

I no longer have a local repro. I enabled the test, change the InlineData values and ran the suite 5 times without error (normally once was enough).

steveharter avatar Apr 26 '17 21:04 steveharter

@steveharter can you please check if you hit it on the CI machine in a loop? If not, I guess we should close it as no repro, at least until next failure in CI. Thoughts?

karelz avatar May 02 '17 00:05 karelz

I originally thought this might be dotnet/corefx#16516 which we currently believe it's caused by a Windows bug. This is happening on both Linux and Windows.

CIPop avatar May 03 '17 22:05 CIPop

I can repro after running the HttpFunctional tests in a loop. Out of 32 runs, it repro'd twice.

What I did to repro:

  1. Comment out the [ActiveIssue(9543)]
  2. Change [InlineData] values from 6,3 to 666,333
  3. Run all of the HttpFunctional tests in a loop on my local Windows 10 machine

steveharter avatar May 04 '17 17:05 steveharter

@CIPop needs some more traces - @steveharter can you please help? (@CIPop will try to repro locally first)

karelz avatar May 04 '17 18:05 karelz