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()
{
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();
it != listen_sockets.end(); ++it)
close(*it);

View File

@ -250,6 +250,15 @@ SharedUnit* get_shared_unit(Request* context, String file_name)
{
su = new SharedUnit();
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 fl_excl = flock(fdlock, LOCK_EX);

View File

@ -18,7 +18,7 @@ typedef long long s64;
typedef std::string String;
#define DEBUG_MEMORY_OFF;
#define GLOBAL_ARENA_ALLOCATOR;
#define NO_GLOBAL_ARENA_ALLOCATOR;
struct MemoryArena {
@ -31,7 +31,7 @@ struct MemoryArena {
{
name = _name;
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);
}
@ -43,7 +43,7 @@ struct MemoryArena {
void clear()
{
#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
size = 0;
}
@ -60,7 +60,7 @@ struct MemoryArena {
}
size += size_aligned;
#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
return(result);
}

View File

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