You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
close_syscall on a socket could block when another thread/cage is waiting for connections with accept_syscall or attempts a blocking send() using same duplicated socket file descriptor. This behavior is not expected. To reproduce:
create a client socket and server socket (AF_INET)
make a fork, now both client and server sockets were duplicated
on server cage, close the client socket, then let the server socket accept
on client cage, close the server socket, then connect to the server
if accept on server cage is called before close on client cage, deadlock would occur
Why this behavior
The reason being that the sockethandler is hold with read access for the entire time the server socket is waiting for connection in accept, and in close, a write access needs to be acquired in order to decrement its pipe reference counter. So that would mean if a socket is accept for some connections, close the same duplicated socket on another thread/cage would block until accept is finished, which could cause some program undergo unexpected deadlock (the example above).
How is this tested?
This behavior is tested and confirmed in c, that no blocking should be produced on close when another thread is calling accept
The text was updated successfully, but these errors were encountered:
rennergade
changed the title
close_syscall could block when another thread is using accept_syscall with same duplicated socket fd
Close Syscall for sockets can deadlock if other thread is in blocking network call
Sep 3, 2024
Description
close_syscall
on a socket could block when another thread/cage is waiting for connections withaccept_syscall
or attempts a blocking send() using same duplicated socket file descriptor. This behavior is not expected. To reproduce:fork
, now both client and server sockets were duplicatedclose
the client socket, then let the server socketaccept
close
the server socket, thenconnect
to the serveraccept
on server cage is called beforeclose
on client cage, deadlock would occurWhy this behavior
The reason being that the
sockethandler
is hold with read access for the entire time the server socket is waiting for connection inaccept
, and inclose
, a write access needs to be acquired in order to decrement its pipe reference counter. So that would mean if a socket isaccept
for some connections,close
the same duplicated socket on another thread/cage would block untilaccept
is finished, which could cause some program undergo unexpected deadlock (the example above).How is this tested?
This behavior is tested and confirmed in c, that no blocking should be produced on
close
when another thread is callingaccept
The text was updated successfully, but these errors were encountered: