Broken Pipe in SockSend (rxsock)

Developers
2009-03-21
2012-08-14
  • Mike Protts

    Mike Protts - 2009-03-21

    I've come across a problem with rexx terminating with 'Broken pipe' if using socksend and the client closes the connection part way through sending (I'd uses sockselect to check for the send socket being available).

    The problem seems to be that when the client closes the connection while the send is active (in this case using curl and then terminate with ctrl-C) there is a SIGPIPE generated (about 90% of the time), and rexx then terminates immediately. The sample code below is called in a long running loop to send hundreds of MB, so it is easy to trigger.

    I have written and tested a simple patch (below) to rexutils/rxsock.c, but I'd be happier if someone else can check I've not been too simplistic. The patch simply adds an ignore action to the SIGPIPE handler. I've not been able to identify any particular problem with ignoring a SIGPIPE, but there may be other circumstances that might indicate saving the current status and restoring after the c socket call.

    Cheers
    Mike

    sample code:

    use arg data
    receive_sock.0 = 0
    send_sock.0 = 1
    send_sock.1 = self~socket()
    err_sock.0 = 1
    err_sock.1 = self~socket()
    rc = SockSelect('RECEIVE_SOCK.', 'SEND_SOCK.', 'ERR_SOCK.', 3)
    Select
    When (rc = 0) then do
    Say 'Send Timeout'
    end
    When (rc < 0) then do
    say 'SockSelect' rc errno SockPSock_Errno() SockSock_Errno()
    end
    otherwise do
    if (err_sock.0 = 1) then do
    say 'Error on' err_sock.1
    return 99
    end
    rc = SockSend(send_sock.1, data)
    if (rc > 0) then do
    rc = 0
    end
    else do
    say 'send error' rc errno SockPSock_Errno() SockSock_Errno()
    end
    end
    end
    ===============

    Patch:

    ooRexx-3.2.0/rexutils/rxsock.c Sun Oct 7 23:04:11 2007
    --- ooRexx-3.2.0.mike/rexutils/rxsock.c Sat Mar 21 18:49:32 2009
    ***
    74,79 ****
    --- 74,80 ----

    #include <ctype.h>
    #include <setjmp.h>
    + #include <signal.h>

    /*------------------------------------------------------------------
    * Windows includes


    922,927
    --- 923,929 ----
    int i;
    ULONG ulRc;
    RexxFunctionHandler
    pRxFunc;
    + struct sigaction new_action, old_action;
    #ifdef WIN32
    WORD wVersionRequested;
    WSADATA wsaData;
    **
    965,970

    --- 967,977 ----
    /---------------------------------------------------------------
    * call function
    ---------------------------------------------------------------*/
    + new_action.sa_handler = SIG_IGN;
    + sigemptyset (&new_action.sa_mask);
    + new_action.sa_flags = 0;
    + sigaction (SIGPIPE, &new_action, NULL);
    +
    ulRc = pRxFunc(name,argc,argv,qName,retStr);

     /*---------------------------------------------------------------
    

    ==========

     
    • Mark Miesfeld

      Mark Miesfeld - 2009-03-21

      Hi Mike,

      Thanks for this. I don't have time to look at it right now and I'm afraid it will get lost in the shuffle.

      It would be better for you to open a bug for this behavior and attach your patch to the bug. You can go to the Tracker tab rather than the Forums tab an use the "Bugs" tracker.

      Just copy and paste your explanation into the bug and attach the patch.

      --
      Mark Miesfeld

       
    • Mike Protts

      Mike Protts - 2009-03-21

      Hi Mark,

      I'd spotted the bug tracker and added it there.

      Thanks
      Mike

       

Log in to post a comment.