xasync: cancel and queue-termination races (cleanup while DoWork runs, XTaskQueueTerminate ignores wait, threads never capped) #228
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from avatarmanz/VIctory-7900XTX. Originally posted by kekonn on 2026-11-26T12:04:28Z.
These are confirmed, but each fix is larger than a quick change. The narrow
pending_withuse-after-free is issue 1.All in
crates/victory-hle/src/modules/xasync.rs:XAsyncCancel(726-734) checksdone, callsOP_CANCEL, thencomplete_call(E_ABORT)→release→OP_CLEANUP, without waiting for aDoWorkalready running on the pool (~619-627) or a provider completing at the same moment. A title provider that frees its context inOP_CLEANUP(the usual GDK pattern) can have it freed under a runningDoWork. Sketch (~35 lines, medium risk): add an in-flight count toCall, withenter()/leave()aroundDoWorkandOP_CANCEL, and deferOP_CLEANUPuntil the count reaches 0. (TheXAsyncRunvariant, which reportsE_ABORTwhile the title's work still runs, needs more than this.)waitand fires the terminated callback straight away. Tasks already in the globalPOOL(~122), or taken fromdelayed(~240), still run after termination.drain(..)(~404) also cancels tasks of other composite queues that share theArc<Port>(~325-332).Arc<Queue>for the whole delay (~237). Every spawn runs the title's DllMains (victory-loaderthreads.rs~252).complete_callholdscall.donewhilerelease()runsOP_CLEANUP(673-689). A three-statedone(PENDING, COMPLETING, DONE) would move cleanup outside the lock. A deadlock needs a title cleanup that blocks on a thread already inside cancel for the same call.Upstream: no open PR touches
xasync.rs.Generated by Claude Code
Imported from avatarmanz/VIctory-7900XTX. Originally posted by illuminatedfellow on 2026-11-26T16:41:41Z.
Status of the four items, and a proposal for the one that needs a policy decision.
Covered: items 1 (cleanup under a running DoWork) and 2 (
XTaskQueueTerminate) are in #244. Its commit message says what it leaves: "worker threads are still uncapped, and complete_call still runs an immediate cleanup under the call's lock" — i.e. items 3 and 4. Both live in code #244 rewrites, so anything for them should build on #244.Item 3 is three separate things:
Idle workers never exit. Mechanical: wait on
readywith a timeout (say 30 s) and exit if still idle and more than a small floor (say 4) are left. Every exit also runs the title'sDLL_THREAD_DETACH, so keeping a floor matters.One OS thread per delayed callback. Mechanical: one timer thread with a
BinaryHeapof(deadline, id, Arc<Queue>, port)andwait_timeoutuntil the earliest deadline. #244's semantics carry over unchanged: the task stays inqueue.delayedand counted inrunningfrom submission, the timer only does what each sleeping thread does now (remove(&id)thendeliver), so termination still cancels it.A burst starts ~one worker per task. This one is not a counting slip: counting workers that are starting changes nothing (
tasks > idle + startingstill spawns one per queued task when submissions outpace startup). One-thread-per-waiting-task is what guarantees "a callback that blocks on another never starves it". Capping needs a policy, e.g.:(a) keeps the no-starvation property; (b) does not. Which would you accept?
Item 4 (cleanup under the call's lock) interacts with #244's new release counting, so it's best done after #244 lands.
Happy to send 3.1 + 3.2 as a PR stacked on #244 (with tests of the pool and timer on their own), and 3.3 once a policy is picked.
(Written with Claude Opus 5.5.)
Imported from avatarmanz/VIctory-7900XTX. Originally posted by kekonn on 2026-11-26T20:38:40Z.
Go ahead. I just recorded these because I spent a 5 hour limit worth of Opus on discovering all these.