fixed bugs that caused socket to close if a child crashes, and also falsely considered a stale SU cache entry to not be re-compile worthy

This commit is contained in:
Udo 2021-12-05 01:54:53 +00:00
parent f77581114c
commit 0685fdf29a
5 changed files with 22 additions and 9 deletions

Binary file not shown.

View File

@ -81,6 +81,9 @@ FastCGIServer::FastCGIServer() :
FastCGIServer::~FastCGIServer() FastCGIServer::~FastCGIServer()
{ {
if(my_pid != parent_pid) // if we're a child process, we must not close the handles
return;
for (std::vector<int>::iterator it = listen_sockets.begin(); for (std::vector<int>::iterator it = listen_sockets.begin();
it != listen_sockets.end(); ++it) it != listen_sockets.end(); ++it)
close(*it); close(*it);

View File

@ -250,6 +250,15 @@ SharedUnit* get_shared_unit(Request* context, String file_name)
{ {
su = new SharedUnit(); su = new SharedUnit();
setup_unit_paths(context, su, file_name); setup_unit_paths(context, su, file_name);
if(!do_recompile)
{
// if we didn't decide to force recompile yet, we need to check
// (this case should only happen if the SU cache for that entry is cold
// but the SO itself exists _AND_ is stale)
su->last_compiled = file_mtime(su->so_name);
if(su->last_compiled < mod_time || mod_time == 0)
do_recompile = true;
}
int fdlock = open((su->so_name+".lock").c_str(), O_RDWR | O_CREAT, 0666 ); int fdlock = open((su->so_name+".lock").c_str(), O_RDWR | O_CREAT, 0666 );
int fl_excl = flock(fdlock, LOCK_EX); int fl_excl = flock(fdlock, LOCK_EX);

View File

@ -18,7 +18,7 @@ typedef long long s64;
typedef std::string String; typedef std::string String;
#define DEBUG_MEMORY_OFF; #define DEBUG_MEMORY_OFF;
#define GLOBAL_ARENA_ALLOCATOR; #define NO_GLOBAL_ARENA_ALLOCATOR;
struct MemoryArena { struct MemoryArena {
@ -31,7 +31,7 @@ struct MemoryArena {
{ {
name = _name; name = _name;
capacity = cap; capacity = cap;
printf("(i) memory arena %s created with capacity of %llu bytes\n", name.c_str(), capacity); printf("(i) memory arena '%s' created with capacity of %llu bytes\n", name.c_str(), capacity);
data = (u8*)malloc(cap); data = (u8*)malloc(cap);
} }
@ -43,7 +43,7 @@ struct MemoryArena {
void clear() void clear()
{ {
#ifdef DEBUG_MEMORY #ifdef DEBUG_MEMORY
printf("(i) memory arena %s cleared after high mark of %llu bytes\n", name.c_str(), size); printf("(i) memory arena '%s' cleared after high mark of %llu bytes\n", name.c_str(), size);
#endif #endif
size = 0; size = 0;
} }
@ -60,7 +60,7 @@ struct MemoryArena {
} }
size += size_aligned; size += size_aligned;
#ifdef DEBUG_MEMORY #ifdef DEBUG_MEMORY
printf("(i) memory arena %s [+%llu]:%p alloc %llu/%llu bytes\n", name.c_str(), size, result, size_needed, size_aligned); printf("(i) memory arena '%s' [+%llu]:%p alloc %llu/%llu bytes\n", name.c_str(), size, result, size_needed, size_aligned);
#endif #endif
return(result); return(result);
} }

View File

@ -4,12 +4,13 @@
FastCGIServer server; FastCGIServer server;
ServerState server_state; ServerState server_state;
MemoryArena* request_arena; MemoryArena* request_arena = 0;
int handle_request(FastCGIRequest& request) { int handle_request(FastCGIRequest& request) {
// This is always the first event to occur. It occurs when the // This is always the first event to occur. It occurs when the
// server receives all parameters. There may be more data coming on the // server receives all parameters. There may be more data coming on the
// standard input stream. // standard input stream.
request.request_arena = request_arena;
request.time_init = microtime(); request.time_init = microtime();
if (request.params.count("REQUEST_URI")) if (request.params.count("REQUEST_URI"))
return 0; // OK, continue processing return 0; // OK, continue processing
@ -66,8 +67,6 @@ int handle_complete(FastCGIRequest& request) {
} }
// printf("(i) request ready\n"); // printf("(i) request ready\n");
//current_memory_arena = request_arena;
//request_arena->clear();
request.invoke(request.params["SCRIPT_FILENAME"]); request.invoke(request.params["SCRIPT_FILENAME"]);
switch_to_system_alloc(); switch_to_system_alloc();
@ -100,12 +99,15 @@ int handle_complete(FastCGIRequest& request) {
void listen_for_connections() void listen_for_connections()
{ {
//request_arena = new MemoryArena(server_state.config.MAX_MEMORY, "request");
signal(SIGSEGV, on_segfault);
server.request_handler(&handle_request); server.request_handler(&handle_request);
server.data_handler(&handle_data); server.data_handler(&handle_data);
server.complete_handler(&handle_complete); server.complete_handler(&handle_complete);
request_arena = new MemoryArena(server_state.config.MAX_MEMORY, "request");
for(;;) for(;;)
{ {
//if(request_arena) request_arena->clear();
//current_memory_arena = request_arena;
server.process(); server.process();
} }
} }
@ -114,7 +116,6 @@ int main(int argc, char** argv)
{ {
printf("(P) Starting parent server PID:%i\n", getpid()); printf("(P) Starting parent server PID:%i\n", getpid());
signal(SIGSEGV, on_segfault);
signal(SIGCHLD, on_child_exit); signal(SIGCHLD, on_child_exit);
srand(time()); srand(time());