@@ -70,7 +70,9 @@ public bool UnsafeConnectionNtlmAuthentication
70
70
{
71
71
return ;
72
72
}
73
- lock ( ( DisconnectResults as ICollection ) . SyncRoot )
73
+
74
+ var disconnectResults = DisconnectResults ;
75
+ lock ( ( disconnectResults as ICollection ) . SyncRoot )
74
76
{
75
77
if ( _unsafeConnectionNtlmAuthentication == value )
76
78
{
@@ -79,7 +81,7 @@ public bool UnsafeConnectionNtlmAuthentication
79
81
_unsafeConnectionNtlmAuthentication = value ;
80
82
if ( ! value )
81
83
{
82
- foreach ( DisconnectAsyncResult result in DisconnectResults . Values )
84
+ foreach ( DisconnectAsyncResult result in disconnectResults . Values )
83
85
{
84
86
result . AuthenticatedConnection = null ;
85
87
}
@@ -694,7 +696,13 @@ public HttpListenerContext EndGetContext(IAsyncResult asyncResult)
694
696
// assurance that we do this only for NTLM/Negotiate is not here, but in the
695
697
// code that caches WindowsIdentity instances in the Dictionary.
696
698
DisconnectAsyncResult ? disconnectResult ;
697
- DisconnectResults . TryGetValue ( connectionId , out disconnectResult ) ;
699
+
700
+ var disconnectResults = DisconnectResults ;
701
+ lock ( ( disconnectResults as ICollection ) . SyncRoot )
702
+ {
703
+ disconnectResults . TryGetValue ( connectionId , out disconnectResult ) ;
704
+ }
705
+
698
706
if ( UnsafeConnectionNtlmAuthentication )
699
707
{
700
708
if ( authorizationHeader == null )
@@ -1327,7 +1335,12 @@ private static void RegisterForDisconnectNotification(HttpListenerSession sessio
1327
1335
// Need to make sure it's going to get returned before adding it to the hash. That way it'll be handled
1328
1336
// correctly in HandleAuthentication's finally.
1329
1337
disconnectResult = result ;
1330
- session . Listener . DisconnectResults [ connectionId ] = disconnectResult ;
1338
+
1339
+ var disconnectResults = session . Listener . DisconnectResults ;
1340
+ lock ( ( disconnectResults as ICollection ) . SyncRoot )
1341
+ {
1342
+ disconnectResults [ connectionId ] = disconnectResult ;
1343
+ }
1331
1344
}
1332
1345
1333
1346
if ( statusCode == Interop . HttpApi . ERROR_SUCCESS && HttpListener . SkipIOCPCallbackOnSuccess )
@@ -1646,8 +1659,21 @@ private void HandleDisconnect()
1646
1659
{
1647
1660
HttpListener listener = _listenerSession . Listener ;
1648
1661
1649
- if ( NetEventSource . Log . IsEnabled ( ) ) NetEventSource . Info ( this , $ "DisconnectResults { listener . DisconnectResults } removing for _connectionId: { _connectionId } ") ;
1650
- listener . DisconnectResults . Remove ( _connectionId ) ;
1662
+ var disconnectResults = listener . DisconnectResults ;
1663
+ if ( NetEventSource . Log . IsEnabled ( ) )
1664
+ {
1665
+ string ? results ;
1666
+ lock ( ( disconnectResults as ICollection ) . SyncRoot )
1667
+ {
1668
+ results = disconnectResults . ToString ( ) ;
1669
+ }
1670
+ NetEventSource . Info ( this , $ "DisconnectResults { results } removing for _connectionId: { _connectionId } ") ;
1671
+ }
1672
+
1673
+ lock ( ( disconnectResults as ICollection ) . SyncRoot )
1674
+ {
1675
+ disconnectResults . Remove ( _connectionId ) ;
1676
+ }
1651
1677
1652
1678
// Cached identity is disposed with the session context
1653
1679
Session ? . Dispose ( ) ;
0 commit comments