File tree 2 files changed +55
-0
lines changed
libraries/System.Net.Sockets/tests/FunctionalTests
native/libs/System.Native
2 files changed +55
-0
lines changed Original file line number Diff line number Diff line change @@ -586,6 +586,56 @@ public async Task ReceiveFrom_EndPoints_Correct(bool useAsync)
586
586
}
587
587
}
588
588
589
+ [ ConditionalFact ( typeof ( Socket ) , nameof ( Socket . OSSupportsUnixDomainSockets ) ) ]
590
+ [ ActiveIssue ( "https://github.com/dotnet/runtime/issues/52124" , TestPlatforms . iOS | TestPlatforms . tvOS | TestPlatforms . MacCatalyst ) ]
591
+ public async Task UnixDomainSocket_Receive_GetsCanceledByDispose ( )
592
+ {
593
+ string path = GetRandomNonExistingFilePath ( ) ;
594
+ var endPoint = new UnixDomainSocketEndPoint ( path ) ;
595
+
596
+ using ( var server = new Socket ( AddressFamily . Unix , SocketType . Stream , ProtocolType . Unspecified ) )
597
+ using ( var client = new Socket ( AddressFamily . Unix , SocketType . Stream , ProtocolType . Unspecified ) )
598
+ {
599
+ server . Bind ( endPoint ) ;
600
+ server . Listen ( 1 ) ;
601
+
602
+ client . Connect ( endPoint ) ;
603
+ int msDelay = 100 ;
604
+ bool readFailed = false ;
605
+ byte [ ] buffer = new byte [ 100 ] ;
606
+ using ( Socket accepted = server . Accept ( ) )
607
+ {
608
+ while ( msDelay < 10_000 )
609
+ {
610
+ Task disposeTask = Task . Run ( ( ) =>
611
+ {
612
+ Thread . Sleep ( msDelay ) ;
613
+ client . Dispose ( ) ;
614
+ } ) ;
615
+
616
+ try
617
+ {
618
+ client . Receive ( buffer ) ;
619
+ }
620
+ catch ( SocketException )
621
+ {
622
+ await disposeTask ;
623
+ readFailed = true ;
624
+ break ;
625
+ }
626
+ catch ( ObjectDisposedException )
627
+ {
628
+ await disposeTask ;
629
+ // Dispose happened before the operation, retry.
630
+ msDelay *= 2 ;
631
+ continue ;
632
+ }
633
+ }
634
+ }
635
+ Assert . True ( readFailed ) ;
636
+ }
637
+ }
638
+
589
639
private static string GetRandomNonExistingFilePath ( )
590
640
{
591
641
string result ;
Original file line number Diff line number Diff line change @@ -3143,6 +3143,11 @@ int32_t SystemNative_Disconnect(intptr_t socket)
3143
3143
#elif HAVE_DISCONNECTX
3144
3144
// disconnectx causes a FIN close on OSX. It's the best we can do.
3145
3145
err = disconnectx (fd , SAE_ASSOCID_ANY , SAE_CONNID_ANY );
3146
+ if (err != 0 )
3147
+ {
3148
+ // This happens on Unix Domain Sockets as disconnectx is only supported on AF_INET and AF_INET6
3149
+ err = shutdown (fd , SHUT_RDWR );
3150
+ }
3146
3151
#else
3147
3152
// best-effort, this may cause a FIN close.
3148
3153
err = shutdown (fd , SHUT_RDWR );
You can’t perform that action at this time.
0 commit comments