From aa923e05f6af9a51681c1bc50fc840976e5536fd Mon Sep 17 00:00:00 2001 From: Glenn Strauss Date: Sat, 11 Feb 2017 12:35:49 -0500 Subject: [PATCH] [mod_fastcgi,mod_scgi] backend spawn EINTR retry (#2788) When spawning backends, retry blocking connect() to backend if EINTR received when attempting to see if backend is already running. EINTR might be received if a HUP or USR1 signal is received while connecting (or SIGCHLD on systems without SA_RESTART) (expected to occur extremely rarely, but simple to handle properly) x-ref: "FreeBSD/1.4.45/SSL: requests getting stuck in handle-req state occasionally" https://redmine.lighttpd.net/issues/2788 --- src/mod_fastcgi.c | 5 ++++- src/mod_scgi.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/mod_fastcgi.c b/src/mod_fastcgi.c index 48934061..1eed6637 100644 --- a/src/mod_fastcgi.c +++ b/src/mod_fastcgi.c @@ -1001,7 +1001,10 @@ static int fcgi_spawn_connection(server *srv, return -1; } - if (-1 == connect(fcgi_fd, fcgi_addr, servlen)) { + do { + status = connect(fcgi_fd, fcgi_addr, servlen); + } while (-1 == status && errno == EINTR); + if (-1 == status) { /* server is not up, spawn it */ pid_t child; int val; diff --git a/src/mod_scgi.c b/src/mod_scgi.c index 47d9ca17..5660b69f 100644 --- a/src/mod_scgi.c +++ b/src/mod_scgi.c @@ -771,7 +771,10 @@ static int scgi_spawn_connection(server *srv, return -1; } - if (-1 == connect(scgi_fd, scgi_addr, servlen)) { + do { + status = connect(scgi_fd, scgi_addr, servlen); + } while (-1 == status && errno == EINTR); + if (-1 == status) { /* server is not up, spawn in */ pid_t child; int val;