call[fs]cgi: At least for now, simply block when connecting to handler.
authorFredrik Tolf <fredrik@dolda2000.com>
Mon, 12 May 2025 15:59:39 +0000 (17:59 +0200)
committerFredrik Tolf <fredrik@dolda2000.com>
Mon, 12 May 2025 15:59:39 +0000 (17:59 +0200)
It's not optimal, but the naive mtio implementation has the thundering-herd
problem, and this also creates a natural choke-point, transmitting the request
buffering responsibility to the parent handler where it belongs.

The more ideal solution would probably be to let running requests continue
being handled while serializing receving incoming requests and connecting to
the request handler.

src/callfcgi.c
src/callscgi.c

index 83a6c7c..8ff0eff 100644 (file)
@@ -246,27 +246,14 @@ static void startnolisten(void)
 static int sconnect(void)
 {
     int fd;
-    int err;
-    socklen_t errlen;
 
     fd = socket(cafamily, SOCK_STREAM, 0);
-    fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
-    while(1) {
-       if(connect(fd, curaddr, caddrlen)) {
-           if((errno == EINPROGRESS) || (errno == EAGAIN)) {
-               block(fd, EV_WRITE, 30);
-               errlen = sizeof(err);
-               if(getsockopt(fd, SOL_SOCKET, SO_ERROR, &err, &errlen) || ((errno = err) != 0)) {
-                   close(fd);
-                   return(-1);
-               }
-               return(fd);
-           }
-           close(fd);
-           return(-1);
-       }
-       return(fd);
+    if(connect(fd, curaddr, caddrlen)) {
+       close(fd);
+       return(-1);
     }
+    fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
+    return(fd);
 }
 
 static int econnect(void)
index 60c72ac..ee46ac1 100644 (file)
@@ -233,27 +233,14 @@ static void startnolisten(void)
 static int sconnect(void)
 {
     int fd;
-    int err;
-    socklen_t errlen;
 
     fd = socket(cafamily, SOCK_STREAM, 0);
-    fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
-    while(1) {
-       if(connect(fd, curaddr, caddrlen)) {
-           if((errno == EINPROGRESS) || (errno == EAGAIN)) {
-               block(fd, EV_WRITE, 30);
-               errlen = sizeof(err);
-               if(getsockopt(fd, SOL_SOCKET, SO_ERROR, &err, &errlen) || ((errno = err) != 0)) {
-                   close(fd);
-                   return(-1);
-               }
-               return(fd);
-           }
-           close(fd);
-           return(-1);
-       }
-       return(fd);
+    if(connect(fd, curaddr, caddrlen)) {
+       close(fd);
+       return(-1);
     }
+    fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
+    return(fd);
 }
 
 static int econnect(void)