fix(webhook): avoid lock-held awaits in server lifecycle paths#1168
fix(webhook): avoid lock-held awaits in server lifecycle paths#1168zmanian merged 3 commits intonearai:stagingfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical issue where Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
The changes correctly address the issue of lock-held awaits by introducing a begin_shutdown method to synchronously extract shutdown primitives. This allows asynchronous waiting for the server task to complete to occur outside of the WebhookServer mutex, thereby improving concurrency and preventing potential deadlocks during shutdown and restart operations. The refactoring in main.rs effectively utilizes this new pattern.
zmanian
left a comment
There was a problem hiding this comment.
Review: Extract shutdown primitives before dropping mutex lock
Clean fix for a classic Tokio anti-pattern. Holding a mutex across .await (the server handle join) could deadlock if any other task needs the lock during shutdown.
Positives:
begin_shutdown()cleanly separates handle extraction from async shutdown work- Take-once semantics ensure idempotent shutdown
- Test verifies second call returns
None main.rsupdated to use the lock-free pattern
LGTM.
…i#1168) * fix(webhook): avoid holding mutex across async shutdown * test(webhook): add regression coverage for begin_shutdown split path * test(webhook): satisfy no-panics rule in begin_shutdown regression
…i#1168) * fix(webhook): avoid holding mutex across async shutdown * test(webhook): add regression coverage for begin_shutdown split path * test(webhook): satisfy no-panics rule in begin_shutdown regression
Summary
tokio::sync::Mutex<WebhookServer>across async await points during shutdownWebhookServer::begin_shutdown()to split sync state extraction from async shutdown waitsWhy
Issue #869 reports lock guards being held across async I/O boundaries in webhook paths, which can block concurrent webhook processing or graceful shutdown.
Testing
cargo fmt --allcargo test -q shutdown_completes_while_process_message_blocked --package ironclawcargo test -q test_restart_with_addr_rebinds_listener --package ironclawCloses #869