Handle immediate call to Script.errorCallback

It's possible for Script.errorCallback to be called as part of the call to
`client.request`. This happens because we eagerly pump the libcurl message loop
to get the request going ASAP. For very obvious failures (e.g. an invalid URL)
this means that the error callback can be called from `client.request`.

Previously, we were only adding the script to its list _after_ the call to
`client.request`, but the error handler tries to remove the script from the list
.

This commit changes the order so that the script is first added to the list
and then the request is made.
This commit is contained in:
Karl Seguin
2026-01-06 17:03:27 +08:00
parent 0b221615b7
commit a845b2e35e

View File

@@ -239,8 +239,17 @@ pub fn addFromElement(self: *ScriptManager, comptime from_parser: bool, script_e
}; };
const is_blocking = script.mode == .normal; const is_blocking = script.mode == .normal;
if (is_blocking == false) {
self.scriptList(script).append(&script.node);
}
if (remote_url) |url| { if (remote_url) |url| {
errdefer script.deinit(true); errdefer {
if (is_blocking == false) {
self.scriptList(script).remove(&script.node);
}
script.deinit(true);
}
var headers = try self.client.newHeaders(); var headers = try self.client.newHeaders();
try page.requestCookie(.{}).headersForRequest(page.arena, url, &headers); try page.requestCookie(.{}).headersForRequest(page.arena, url, &headers);
@@ -271,8 +280,6 @@ pub fn addFromElement(self: *ScriptManager, comptime from_parser: bool, script_e
} }
if (is_blocking == false) { if (is_blocking == false) {
const list = self.scriptList(script);
list.append(&script.node);
return; return;
} }