Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Program received signal SIGPIPE, Broken pipe

People also ask

What can cause SIGPIPE?

Another cause of SIGPIPE is when you try to output to a socket that isn't connected. See Sending Data. Resource lost. This signal is generated when you have an advisory lock on an NFS file, and the NFS server reboots and forgets about your lock.

How do you handle a SIGPIPE signal?

You generally want to ignore the SIGPIPE and handle the error directly in your code. This is because signal handlers in C have many restrictions on what they can do. The most portable way to do this is to set the SIGPIPE handler to SIG_IGN . This will prevent any socket or pipe write from causing a SIGPIPE signal.

How does Python handle broken pipe exception?

Approach 2: We can handle this type of error by using the functionality of try/catch block which is already approved by the python manual and is advised to follow such procedure to handle the errors. Example: Python3.

What is Sig_ign?

SIG_IGN specifies that the signal should be ignored. Your program generally should not ignore signals that represent serious events or that are normally used to request termination. You cannot ignore the SIGKILL or SIGSTOP signals at all.


The process received a SIGPIPE. The default behaviour for this signal is to end the process.

A SIGPIPE is sent to a process if it tried to write to a socket that had been shutdown for writing or isn't connected (anymore).

To avoid that the program ends in this case, you could either

  • make the process ignore SIGPIPE

    #include <signal.h>
    
    int main(void)
    {
      sigaction(SIGPIPE, &(struct sigaction){SIG_IGN}, NULL);
    
      ...
    

    or

  • install an explicit handler for SIGPIPE (typically doing nothing):

    #include <signal.h>
    
    void sigpipe_handler(int unused)
    {
    }
    
    int main(void)
    {
      sigaction(SIGPIPE, &(struct sigaction){sigpipe_handler}, NULL);
    
      ...
    

In both cases send*()/write() would return -1 and set errno to EPIPE.


When debugging with 'gdb', it is possible to manually disable SIGPIPE as follows:

(gdb) handle SIGPIPE nostop


A workaround for SIGPIPE, you can ignore this signal by this code:

#include <signal.h>

/* Catch Signal Handler functio */
void signal_callback_handler(int signum){

        printf("Caught signal SIGPIPE %d\n",signum);
}

in your code (main or globally)

/* Catch Signal Handler SIGPIPE */
signal(SIGPIPE, signal_callback_handler);

You have written to a connection that has already been closed by the peer.


I sort of experienced the same problem and it let me to this SO post. I got sporadic SIGPIPE signals causing crashes of my fastcgi C program run by nginx. I tried to signal(SIGPIPE, SIG_IGN); without luck, it kept crashing.

The reason was that nginx's temp dir had a permission problem. Fixing the permissions solved the SIGPIPE problem. Details here on how to fix and more here.