0

Imagine I have a server that has a connected tcp socket with a remote client. If the server dies because of a segfault, will the socket be closed by the OS and the client be notified with a RST or will the client never know and the sockets stay open on client and server computers ?

boredaf
  • 181

1 Answers1

1

If the process is in the debugger and it segfaults, or if it catches the segfault signal, it technically doesn't die and nothing immediately happens to the socket.

However, if the process actually dies, the segfault condition is not particularly special, and one end of the socket would close just like it would if the process had exited any other way, similar to the shutdown(2) system call.

If any data is in kernel buffers for the socket, it will be allowed to drain. (However, unwritten data in STDIO buffers may be lost.) The remote end of the socket will see an EOF after it reads the last data, and will receive a SIGPIPE signal if it tries to write to the socket.

user10489
  • 6,740