Unable to start a python webservice from a mod_perl context
I'm trying to start the program [websockify][1], which is a python websockets proxy server used for [noVNC][2], from a mod_perl context. The process starts, but is unable to handle any requests. When I connect strace to the process I get the following message during a request (the interesting part is the **Bad file descriptor**):

    select(1, [0], [], [], {1, 0})          = 0 (Timeout)
    select(1, [0], [], [], {1, 0})          = 0 (Timeout)
    select(1, [0], [], [], {1, 0})          = 1 (in [0], left {0, 924295})
    accept(0, {sa_family=AF_INET, sin_port=htons(3481), sin_addr=inet_addr("xxx.xxx.xxx.151")}, [16]) = 3
    write(1, "  1: handler exception: [Errno 9] Bad file descriptor\n", 54) = -1 EBADF (Bad file descriptor)
    close(3)                                = 0
    select(1, [0], [], [], {1, 0})          = 0 (Timeout)
    select(1, [0], [], [], {1, 0})          = 0 (Timeout)

The code for starting the process is as follows:

    $SIG{CHLD} = 'IGNORE'; # prevent zombie processes by letting the init process collecting the forked processes
    defined ($pid = fork()) or die "Cannot fork!";
    if (!$pid) {
        chdir '/';
        open STDIN, '/dev/null';
        open STDOUT, '>/dev/null';
        setsid();
        exec("somepath/websockify xxx.xxx.xxx.xxx:10080 xxx.xxx.xxx.xxx:5900") or die "Cannot start the Websockify server: $!";
    }

Since websockify works perfect when started from bash, I think it has something to do with the mod_perl and apache context. Somehow the file descriptor is not valid anymore? Does anyone has a clue? Thanks!


  [1]: https://github.com/kanaka/websockify
  [2]: http://kanaka.github.com/noVNC/
Unable to start a python webservice from a mod_perl context
===

I'm trying to start the program [websockify][1], which is a python websockets proxy server used for [noVNC][2], from a mod_perl context. The process starts, but is unable to handle any requests. When I connect strace to the process I get the following message during a request (the interesting part is the **Bad file descriptor**):

    select(1, [0], [], [], {1, 0})          = 0 (Timeout)
    select(1, [0], [], [], {1, 0})          = 0 (Timeout)
    select(1, [0], [], [], {1, 0})          = 1 (in [0], left {0, 924295})
    accept(0, {sa_family=AF_INET, sin_port=htons(3481), sin_addr=inet_addr("xxx.xxx.xxx.151")}, [16]) = 3
    write(1, "  1: handler exception: [Errno 9] Bad file descriptor\n", 54) = -1 EBADF (Bad file descriptor)
    close(3)                                = 0
    select(1, [0], [], [], {1, 0})          = 0 (Timeout)
    select(1, [0], [], [], {1, 0})          = 0 (Timeout)

The code for starting the process is as follows:

    $SIG{CHLD} = 'IGNORE'; # prevent zombie processes by letting the init process collecting the forked processes
    defined ($pid = fork()) or die "Cannot fork!";
    if (!$pid) {
        chdir '/';
        open STDIN, '/dev/null';
        open STDOUT, '>/dev/null';
        setsid();
        exec("somepath/websockify xxx.xxx.xxx.xxx:10080 xxx.xxx.xxx.xxx:5900") or die "Cannot start the Websockify server: $!";
    }

Since websockify works perfect when started from bash, I think it has something to do with the mod_perl and apache context. Somehow the file descriptor is not valid anymore? Does anyone has a clue? Thanks!


  [1]: https://github.com/kanaka/websockify
  [2]: http://kanaka.github.com/noVNC/