fix(inbound): bound the sync prefix of inbound scripts by the method timeout (INB-1, WP7 task 7.6)

This commit is contained in:
Joseph Doherty
2026-12-03 10:01:06 -05:00
parent 6019335ba9
commit 0a62f33ab5
3 changed files with 44 additions and 2 deletions
@@ -625,7 +625,15 @@ public class InboundScriptExecutor
_scriptHandlers[method.Name] = cached; // last-write-wins; concurrent first-callers race benignly
}
handlerTask = cached.Handler(context);
// Start the handler OFF the request thread (INB-1). Script.RunAsync runs the script
// synchronously up to its first incomplete await, so invoking the handler inline would
// hold the request thread with no deadline for any script that does CPU work or a
// blocking call before its first await (TimeoutSeconds and client disconnect both
// ignored, no TIMEOUT, abandoned-execution count stuck at 0). Running it on the pool
// lets WaitAsync bound the WHOLE run; a non-cooperative script is then abandoned and
// counted exactly like one that blocks after an await.
var handler = cached.Handler;
handlerTask = Task.Run(() => handler(context), cts.Token);
var result = await handlerTask.WaitAsync(cts.Token);
var resultJson = result != null