Question

I tested the same testcode (Server - Client) on two systems. In one I am getting a SIGPIPE, in another I am not getting SIGPIPE.

The Test Scenario is something like below:

Client

  1. Connect to a Server
  2. Receive Data from Server
  3. Send Data
  4. Close the Socket

Server

  1. Accept Connection from a Server
  2. Send Data to Client
  3. Receive Data
  4. Send Data
  5. Close the Socket

In one system (Client & Server running on the same system), SIGPIPE is happening randomly on the client or server side.

But, in another system, this problem is not happening with the same test code.

I wonder if broken pipe has something to do with TCP Settings.

Was it helpful?

Solution

You can also ignore SIGPIPE from socket for prevent application crash by this code:

int set = 1;
setsockopt(sd, SOL_SOCKET, SO_NOSIGPIPE, (void *)&set, sizeof(int));

Where sd is socket where you receiving SIGPIPEs.

OTHER TIPS

The SIGPIPE signal is raised if you try to write to a socket that the other end has already closed. There is a race condition here, if one end closes the socket around the same time as the other end attempts to send data - the close notification might be received before or after the send, which is why the SIGPIPE is occuring in one test environment and not the other.

Generally, socket-aware applications should ignore SIGPIPE, and instead synchronously handle the resulting EPIPE error from send().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top