Skip to content

fix(mlx): guard callback installation with callbackLock#54

Merged
missuo merged 2 commits into
missuo:mainfrom
erning:fix/mlx-callback-lock
Apr 6, 2026
Merged

fix(mlx): guard callback installation with callbackLock#54
missuo merged 2 commits into
missuo:mainfrom
erning:fix/mlx-callback-lock

Conversation

@erning

@erning erning commented Apr 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • MLXAsrManager.startSession() wrote callback and callbackCtx without holding callbackLock, while cancel() and invokeCallback() both acquire it. This left a narrow window where an old async task could observe a half-updated callback pair.
  • Wrap the two assignments in callbackLock.lock() / callbackLock.unlock() so all three sites (install, clear, invoke) share the same lock.

Test plan

  • Build succeeds
  • Rapid hold-release cycles with MLX provider — verify no crashes or stale events

erning added 2 commits April 1, 2026 15:15
startSession wrote callback/callbackCtx without holding the lock,
while cancelInternal and invokeCallback both acquire it. This left a
narrow window where an old async task could observe a half-updated
callback pair. Wrap the installation in callbackLock to close the gap.
…talk

Pass the session generation into invokeCallback and verify it under
callbackLock before dispatching. This closes the window where an old
eventTask passes the generation guard, then a new startSession swaps
the callback, and the old task delivers stale events to the new
session's callback.
@missuo missuo merged commit c83948c into missuo:main Apr 6, 2026
@erning erning deleted the fix/mlx-callback-lock branch April 7, 2026 02:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants