--- parser3/src/targets/cgi/parser3.C 2026/10/27 23:38:52 1.388 +++ parser3/src/targets/cgi/parser3.C 2026/11/21 01:27:01 1.392 @@ -5,7 +5,7 @@ Authors: Konstantin Morshnev , Alexandr Petrosian */ -volatile const char * IDENT_PARSER3_C="$Id: parser3.C,v 1.388 2026/10/27 23:38:52 moko Exp $"; +volatile const char * IDENT_PARSER3_C="$Id: parser3.C,v 1.392 2026/11/21 01:27:01 moko Exp $"; #include "pa_config_includes.h" @@ -20,6 +20,7 @@ volatile const char * IDENT_PARSER3_C="$ #include "pa_code_cache.h" #include "pa_websocket.h" #include "pa_os.h" +#include "pa_exec.h" #ifdef _MSC_VER #include @@ -116,7 +117,7 @@ static void pa_log(const char* stamp, co size+=pa_snprintf(line+size, sizeof(line)-size, " [no request info]\n"); const char* slog=parser3_log_filespec(); - int fd=strcmp(slog,"-") ? pa_open(slog, O_WRONLY | O_APPEND | O_CREAT | O_CLOEXEC, 0666) : -1; + int fd=strcmp(slog,"-") ? open(slog, O_WRONLY | O_APPEND | O_CREAT | O_CLOEXEC, 0666) : -1; // not pa_open, it allocates under Windows if(fd<0) fd=STDERR_FILENO; // fallback to stderr PA_UNUSED int ignore_result=write(fd, line, (unsigned int)size); @@ -332,6 +333,11 @@ private: if(!timeout) return; +#ifndef _MSC_VER + if(pa_exec_active_pid) + kill(-pa_exec_active_pid, SIGKILL); // kill the whole process group so nothing is left orphaned +#endif + if(timeout->expired && timeout->kill_process){ // the request is still running after the grace period pa_log_at(timeout->stamp, "response timeout (%d s) exceeded, process killed", timeout->seconds); @@ -343,7 +349,7 @@ private: timeout->expired=1; if(thread_request) - thread_request->set_skip(Request::SKIP_INTERRUPTED); + thread_request->interrupt(); } }; @@ -462,6 +468,10 @@ static void reject_connection(HTTPD_Conn SAPI_Info_HTTPD info(connection); SAPI::send_error(info, "too many connections", "503"); + + // closing the socket with unread request resets the connection and the response can be lost: non-blocking reading for what has arrived + char buf[4096]; + for(int i=0; i<16 && pa_sock_ready(connection.sock, false, 0)>0 && connection.receive(buf, sizeof(buf)); i++); } static void httpd_mode() {