Repository navigation
fix: join side-model workers on server exit - #2827
Merged
Merged
Conversation
On a CPU build, an MLX free that runs after the C runtime's static destructors start aborts with `pure virtual method called`. PR #2742 joined the chat model worker but left the audio, realtime, embedding, image and rerank workers joining only in their unbounded `Drop`, on whichever thread dropped the last `Arc`. Each side provider now exposes `shutdown_and_wait`, sharing the chat worker's `WorkerExitObserver`, and `serve_with_model_provider` keeps one clone of every side `Arc` and joins the side workers first, then the chat worker, on the blocking pool under one `WORKER_EXIT_TIMEOUT` deadline. Side-worker failures log `warn!` and never replace the error that ended serving. The sleeping worker now exits on `Shutdown` without reloading. `join_model_worker_before_exit` takes its timeout as a parameter and reports that a timed-out worker is still running, which a CPU build may abort on; the limitation is documented because model load has no cancellation point. The remote pipeline stage path always shuts the stage down and joins it on the blocking pool, including when the Ctrl-C handler cannot be installed. Validation: cargo fmt --check, clippy on the lib and tests with -D warnings, cargo check, the server build and the startup unit tests pass. The real-model integration tests skip on this host because their checkpoints are absent. Refs #2745
inureyes
force-pushed
the
fix/issue-2745-join-side-workers
branch
from
November 2, 2026 08:06
b808c3d to
310993d
Compare
inureyes
marked this pull request as ready for review
November 2, 2026 08:07
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A CPU build aborts with
pure virtual method calledwhen a worker frees MLX state aftermainreturns. #2742 joined the chat model worker; this PR joins every side worker too, exits a sleeping worker without reloading, bounds and documents the load-in-progress case, and always drains the remote pipeline stage.What changed
shutdown_and_waittoAudioModelProvider,EmbeddingModelProvider,ImageModelProviderandRerankModelProvider, plus an inherent method onRealtimeVoiceChatEngine. Each reusesWorkerExitObserver;Dropkeeps its current join.serve_with_model_providernow keeps one clone of every sideArcand joins the side workers first, then the chat worker, on the blocking pool under a singleWORKER_EXIT_TIMEOUTdeadline. Side-worker failures logwarn!and never replace the error that ended serving. New log line:side model workers exited before process exit.--sleep-idle-secondsnow breaks onModelRequest::Shutdownwithout clearingsleepingor reloading.join_model_worker_before_exittakes its timeout as a parameter. On timeout the warning and returned error say the worker is still running and that a CPU build may abort withpure virtual method calledat exit. The same limitation is documented onWORKER_EXIT_TIMEOUT,ROUTER_SHUTDOWN_TIMEOUTand indocs/server-features.md, since model load has no cancellation point (rejected: adding one is not expressible across the per-family loaders with lazy MLX evaluation).--pp-peerstage path captures the signal result, always shuts the stage down insidetokio::task::spawn_blocking, then returns the signal error if there was one. The select-then-shutdown sequence is a helper unit-tested with a failing signal future and a fake handle. The router half was already fixed in fix(server): join model workers before the process exits #2742.tests/server_exit_joins_worker.rs(Whisper side worker, embedding worker joined before a later--image-modelfailure), the sleeping-worker test, astartup_tests.rstimeout test with a fake worker that sleeps 2 s before reading its channel, and the stage-shutdown test.Test plan
cargo fmt --checkcargo clippy -p mlxcel --lib --tests -- -D warningscargo check -p mlxcel --lib --testscargo build -p mlxcel --bin mlxcel-servercargo test -p mlxcel --lib server::startup::cargo test -p mlxcel --test server_exit_joins_worker(real-model cases skip on this host: the checkpoints are absent)server_exit_joins_workerwith--features cudaand run the 2-host logical PP CI job (not available in this environment)Closes #2745