fix: prevent stale mutation execution
This commit is contained in:
+23
-2
@@ -575,6 +575,17 @@ int handle_complete(FastCGIRequest& request) {
|
||||
};
|
||||
|
||||
String entry_unit = compiler_normalize_unit_path(&request, request.params["SCRIPT_FILENAME"]);
|
||||
String request_method = to_upper(trim(request.params["REQUEST_METHOD"]));
|
||||
bool read_request = request_method == "GET" || request_method == "HEAD" || request_method == "OPTIONS";
|
||||
bool stale_mutation = !request.resources.is_cli && !read_request && compiler_unit_needs_recompile(&request, entry_unit);
|
||||
if(stale_mutation)
|
||||
{
|
||||
compiler_prioritize_unit(&request, entry_unit);
|
||||
request.set_status(503, "Service Unavailable");
|
||||
request.header["Content-Type"] = "text/plain; charset=utf-8";
|
||||
request.header["Retry-After"] = "1";
|
||||
print("The requested code is being updated. Retry this request shortly.\n");
|
||||
}
|
||||
// W7e: every unit runs on wasm. When the artifact is missing or stale
|
||||
// (cold worker, or source edited since the last compile), compile the
|
||||
// unit on demand — get_shared_unit() builds the .wasm side-module — and
|
||||
@@ -593,7 +604,11 @@ int handle_complete(FastCGIRequest& request) {
|
||||
failure_trace = "source: " + request.params["SCRIPT_FILENAME"];
|
||||
};
|
||||
|
||||
if(request.params["UCE_WS"] == "1")
|
||||
if(stale_mutation)
|
||||
{
|
||||
// The response above deliberately bypasses all stale application code.
|
||||
}
|
||||
else if(request.params["UCE_WS"] == "1")
|
||||
{
|
||||
// A WS message the broker forwarded here: rebuild the connection
|
||||
// context the broker passed as params, then run __uce_websocket.
|
||||
@@ -1243,7 +1258,13 @@ void run_proactive_compiler()
|
||||
{
|
||||
try
|
||||
{
|
||||
if(compile_queue.size() == 0 && time_precise() >= next_scan_at)
|
||||
auto priority_units = compiler_take_priority_units(&background_context);
|
||||
for(auto it = priority_units.rbegin(); it != priority_units.rend(); ++it)
|
||||
{
|
||||
compile_queue.erase(std::remove(compile_queue.begin(), compile_queue.end(), *it), compile_queue.end());
|
||||
compile_queue.insert(compile_queue.begin(), *it);
|
||||
}
|
||||
if(compile_queue.size() == 0 && time_precise() >= next_scan_at)
|
||||
{
|
||||
auto tracked_units = compiler_list_known_units(&background_context);
|
||||
StringList existing_units;
|
||||
|
||||
Reference in New Issue
Block a user