@@ -353,26 +353,26 @@ public void BypassMongocryptdClientWhenSharedLibraryTest(
353353 try
354354 {
355355 tcpListener = new TcpListener ( mongocryptdIpAddress , port : mongocryptPort ) ;
356- var listenerThread = new Thread ( new ParameterizedThreadStart ( ThreadStart ) ) { IsBackground = true } ;
356+ tcpListener . Start ( ) ;
357+ var listenerThread = new Thread ( ThreadStart ) { IsBackground = true } ;
358+ listenerThread . Start ( tcpListener ) ;
357359
358360 using ( var clientEncrypted = ConfigureClientEncrypted ( kmsProviderFilter : "local" , extraOptions : extraOptions ) )
359361 {
360362 var coll = GetCollection ( clientEncrypted , __collCollectionNamespace ) ;
361363
362- listenerThread . Start ( tcpListener ) ;
363-
364364 _ = Record . Exception ( ( ) => Insert ( coll , async , new BsonDocument ( "unencrypted", "test") ) ) ;
365+ }
365366
366- if ( listenerThread . Join ( timeout ) )
367- {
368- // This exception is never thrown when mognocryptd mongoClient is not spawned which is expected behavior.
369- // However, if we intentionally break that logic to spawn mongocryptd mongoClient regardless of shared library,
370- // this exception sometimes won't be thrown. In all such cases the spent time in listenerThread.Join is higher
371- // or really close to timeout. So it's unclear why Join doesn't throw in that cases, but that logic is unrelated
372- // to the driver and csfle in particular. We rely on the fact that even if we break this logic,
373- // we run this test more than once.
374- throw new Exception ( $ "Listener accepted a tcp call for moncgocryptd during { timeout } .") ;
375- }
367+ if ( listenerThread . Join ( timeout ) )
368+ {
369+ // This exception is never thrown when mognocryptd mongoClient is not spawned which is expected behavior.
370+ // However, if we intentionally break that logic to spawn mongocryptd mongoClient regardless of shared library,
371+ // this exception sometimes won't be thrown. In all such cases the spent time in listenerThread.Join is higher
372+ // or really close to timeout. So it's unclear why Join doesn't throw in that cases, but that logic is unrelated
373+ // to the driver and csfle in particular. We rely on the fact that even if we break this logic,
374+ // we run this test more than once.
375+ throw new Exception ( $ "Listener accepted a tcp call for moncgocryptd during { timeout } .") ;
376376 }
377377 }
378378 finally
@@ -385,7 +385,6 @@ void ThreadStart(object param)
385385 try
386386 {
387387 var tcpListener = ( TcpListener ) param ;
388- tcpListener . Start ( ) ;
389388 using var client = tcpListener . AcceptTcpClient ( ) ;
390389 // Perform a blocking call to accept requests.
391390 // if we're here, then something queries port 27030.
0 commit comments