avoid request stalls during proactive rebuilds
This commit is contained in:
+31
-3
@@ -296,7 +296,7 @@ String compiler_registry_lock_file_name(Request* context)
|
||||
return(compiler_registry_file_name(context) + ".lock");
|
||||
}
|
||||
|
||||
int compiler_open_lock_file(String file_name, String purpose)
|
||||
int compiler_open_lock_file(String file_name, String purpose, bool nonblocking = false)
|
||||
{
|
||||
(void)purpose;
|
||||
auto lock_dir = dirname(file_name);
|
||||
@@ -309,8 +309,13 @@ int compiler_open_lock_file(String file_name, String purpose)
|
||||
return(fdlock);
|
||||
}
|
||||
fcntl(fdlock, F_SETFD, FD_CLOEXEC);
|
||||
if(flock(fdlock, LOCK_EX) != 0)
|
||||
if(flock(fdlock, LOCK_EX | (nonblocking ? LOCK_NB : 0)) != 0)
|
||||
{
|
||||
if(nonblocking && (errno == EWOULDBLOCK || errno == EAGAIN))
|
||||
{
|
||||
close(fdlock);
|
||||
return(-2);
|
||||
}
|
||||
close(fdlock);
|
||||
printf("(!) Could not lock file %s\n", file_name.c_str());
|
||||
return(-1);
|
||||
@@ -845,7 +850,19 @@ SharedUnit* compiler_get_shared_unit_internal(Request* context, String file_name
|
||||
SharedUnit* su = new SharedUnit();
|
||||
setup_unit_paths(context, su, file_name);
|
||||
|
||||
int fdlock = compiler_open_lock_file(su->wasm_name + ".lock", "shared-unit:" + file_name);
|
||||
int fdlock = compiler_open_lock_file(su->wasm_name + ".lock", "shared-unit:" + file_name, !force_recompile);
|
||||
if(fdlock == -2 && file_exists(su->wasm_name))
|
||||
{
|
||||
auto state = inspect_shared_unit_filesystem(context, su);
|
||||
su->api_declarations = split(file_get_contents(su->api_file_name), "\n");
|
||||
su->last_compiled = state.compiled_time;
|
||||
su->compile_status = "rebuilding";
|
||||
compiler_record_observed_filesystem_state(su, state);
|
||||
context->server->units[file_name] = su;
|
||||
return(su);
|
||||
}
|
||||
if(fdlock == -2)
|
||||
fdlock = compiler_open_lock_file(su->wasm_name + ".lock", "shared-unit:" + file_name);
|
||||
if(fdlock == -1)
|
||||
{
|
||||
su->compiler_messages = "could not open compile lock";
|
||||
@@ -947,6 +964,17 @@ bool compiler_unit_compile_pending(Request* context, String file_name)
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool compiler_unit_compile_in_progress(Request* context, String file_name)
|
||||
{
|
||||
SharedUnit su;
|
||||
setup_unit_paths(context, &su, compiler_normalize_unit_path(context, file_name));
|
||||
int fdlock = compiler_open_lock_file(su.wasm_name + ".lock", "compile-probe", true);
|
||||
if(fdlock == -2)
|
||||
return(true);
|
||||
compiler_close_lock_file(fdlock);
|
||||
return(false);
|
||||
}
|
||||
|
||||
void unit_render(String file_name)
|
||||
{
|
||||
unit_render(file_name, *context);
|
||||
|
||||
@@ -17,6 +17,7 @@ void compile_shared_unit(Request* context, SharedUnit* su);
|
||||
SharedUnit* get_shared_unit(Request* context, String file_name);
|
||||
String compiler_error_page_unit(Request* context, String config_key);
|
||||
bool compiler_unit_compile_pending(Request* context, String file_name);
|
||||
bool compiler_unit_compile_in_progress(Request* context, String file_name);
|
||||
String compiler_site_directory(Request* context);
|
||||
StringList compiler_scan_site_units(Request* context);
|
||||
StringList compiler_list_known_units(Request* context);
|
||||
|
||||
Reference in New Issue
Block a user