Bug 56535 - [MARTIN TEST] [BTLS]: ** MARTIN TEST ** (Race condition in Close())
Summary: [MARTIN TEST] [BTLS]: ** MARTIN TEST ** (Race condition in Close())
Status: ASSIGNED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System (show other bugs)
Version: unspecified
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Martin Baulig
URL:
Depends on:
Blocks:
 
Reported: 2017-05-16 22:49 UTC by Martin Baulig
Modified: 2017-09-13 19:16 UTC (History)
1 user (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments

Description Martin Baulig 2017-05-16 22:49:42 UTC

    
Comment 1 Martin Baulig 2017-05-16 22:51:59 UTC
Using this branch:
https://github.com/baulig/mono/commit/7d3c2f2ba808e8a9827afcc98c74e1ec98bfad61

and a rather complicated test case, we're now reliably getting this exception.
Comment 2 Martin Baulig 2017-05-16 22:52:54 UTC
MonoBtlsSsl.Destroy: 7fbaeb6a70f0
MobileAuthenticatedStream(2): AsyncProtocolRequest(2:3): Start Operation: 0 Mono.Net.Security.AsyncOperation
MobileAuthenticatedStream(2): AsyncProtocolRequest(2:3): ProcessOperation: Initialize
MobileAuthenticatedStream(2): AsyncProtocolRequest(2:3): ProcessOperation - continue
MobileAuthenticatedStream(2): ProcessClose: Initialize
MonoBtlsContext: Close!
Assertion failed: (!ptr->active), function mono_btls_ssl_close, file /Workspace/mono-master/mono/btls/btls-ssl.c, line 63.
Stacktrace:

  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) Mono.Btls.MonoBtlsSsl.mono_btls_ssl_close (intptr) [0x00009] in <7855ab18c63b41c1b4e2bf56b8384c76>:0
  at Mono.Btls.MonoBtlsSsl.Close () [0x00000] in /Workspace/mono-master/mcs/class/System/Mono.Btls/MonoBtlsSsl.cs:438
  at Mono.Btls.MonoBtlsObject.Dispose (bool) [0x0000b] in /Workspace/mono-master/mcs/class/System/Mono.Btls/MonoBtlsObject.cs:122
  at Mono.Btls.MonoBtlsObject.Dispose () [0x00000] in /Workspace/mono-master/mcs/class/System/Mono.Btls/MonoBtlsObject.cs:135
  at Mono.Btls.MonoBtlsContext.Close () [0x00018] in /Workspace/mono-master/mcs/class/System/Mono.Btls/MonoBtlsContext.cs:366
  at Mono.Net.Security.MobileAuthenticatedStream.ProcessClose (Mono.Net.Security.AsyncProtocolRequest,Mono.Net.Security.AsyncOperationStatus) [0x00037] in /Workspace/mono-master/mcs/class/System/Mono.Net.Security/MobileAuthenticatedStream.cs:676
  at Mono.Net.Security.AsyncProtocolRequest.ProcessOperation (Mono.Net.Security.AsyncOperationStatus) [0x000e5] in /Workspace/mono-master/mcs/class/System/Mono.Net.Security/AsyncProtocolRequest.cs:272
  at Mono.Net.Security.AsyncProtocolRequest.ProcessOperation () [0x00027] in /Workspace/mono-master/mcs/class/System/Mono.Net.Security/AsyncProtocolRequest.cs:218
  at Mono.Net.Security.AsyncProtocolRequest.StartOperation () [0x00000] in /Workspace/mono-master/mcs/class/System/Mono.Net.Security/AsyncProtocolRequest.cs:199
  at Mono.Net.Security.AsyncProtocolRequest.StartOperation (Mono.Net.Security.AsyncOperation) [0x00047] in /Workspace/mono-master/mcs/class/System/Mono.Net.Security/AsyncProtocolRequest.cs:189
  at Mono.Net.Security.MobileAuthenticatedStream.StartOperation (Mono.Net.Security.AsyncProtocolRequest&,Mono.Net.Security.BufferOffsetSize2&,Mono.Net.Security.AsyncOperation,Mono.Net.Security.AsyncProtocolRequest,string) [0x0001f] in /Workspace/mono-master/mcs/class/System/Mono.Net.Security/MobileAuthenticatedStream.cs:363
  at Mono.Net.Security.MobileAuthenticatedStream.Close () [0x00022] in /Workspace/mono-master/mcs/class/System/Mono.Net.Security/MobileAuthenticatedStream.cs:742
  at System.IO.Stream.Dispose () [0x00000] in /Workspace/mono-master/mcs/class/referencesource/mscorlib/system/io/stream.cs:260
  at System.Net.Security.SslStream.Dispose (bool) [0x0000d] in /Workspace/mono-master/mcs/class/System/System.Net.Security/SslStream.cs:348
  at System.IO.Stream.Close () [0x00000] in /Workspace/mono-master/mcs/class/referencesource/mscorlib/system/io/stream.cs:248
  at System.IO.Stream.Dispose () [0x00000] in /Workspace/mono-master/mcs/class/referencesource/mscorlib/system/io/stream.cs:260
Comment 3 Martin Baulig 2017-05-16 22:56:07 UTC
So the theory behind this is that MobileAuthenticatedStream maintains all threading synchronization and prevents concurrent access to the same native object.

This class is used by both BTLS and AppleTls.  It looks like we're somehow calling the native Close() while another thread is inside native code.

Note You need to log in before you can comment on or make changes to this bug.