Skip to content

Fixed: stem inconsistencies in the module resolution and rollback loo…#3

Merged
sn merged 1 commit into
mainfrom
chore/timeout-sync
May 17, 2026
Merged

Fixed: stem inconsistencies in the module resolution and rollback loo…#3
sn merged 1 commit into
mainfrom
chore/timeout-sync

Conversation

@sn
Copy link
Copy Markdown
Contributor

@sn sn commented May 17, 2026

This pull request makes significant improvements to the thread-safety, timeout handling, and error notification mechanisms in the HookRegistry class. The changes ensure that hook registration, unregistration, and dispatch are safe under concurrent access, improve the reliability of timeout enforcement for synchronous hooks, and enhance plugin error handling, especially for async error callbacks.

Thread-safety improvements:

  • All mutations and lookups of the internal hooks dictionary (_hooks) are now protected by a reentrant lock (threading.RLock), preventing race conditions when hooks are registered, unregistered, or dispatched from multiple threads. Iteration over hooks now uses a snapshot to avoid concurrent modification issues. [1] [2] [3] [4] [5] [6]

Timeout handling improvements:

  • Synchronous hook execution with timeouts now uses a shared class-level ThreadPoolExecutor instead of creating a new one per call. This prevents the main thread from blocking indefinitely if a hook times out, and avoids orphaned worker threads blocking process exit. [1] [2] [3]
  • Async hook dispatch no longer double-nests thread pools for sync hooks; timeouts are enforced at the asyncio boundary, using only one thread per timed hook. [1] [2]

Plugin error notification:

  • Plugin on_error callbacks are now handled more robustly: async error handlers are properly awaited in trigger_async, and in sync mode, async error handlers are closed with a warning to avoid unawaited coroutine warnings. [1] [2] [3] [4] [5]

Other improvements:

  • The event pattern matching logic for wildcards is clarified and made stricter: * now matches only non-empty segments, preventing accidental matches with empty segments.
  • The registry now exposes the last set of errors encountered during dispatch for programmatic inspection, especially useful with the collect_all error strategy. [1] F64c90f2L447R447, [2]

These changes make the hook system safer, more predictable, and easier to debug in concurrent and plugin-heavy environments.…k timeouts

@sn sn self-assigned this May 17, 2026
@sn sn merged commit c2fa40e into main May 17, 2026
6 checks passed
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.

1 participant