Skip to content

apollo_propeller: wake poll from on_behaviour_event#13334

Merged
sirandreww-starkware merged 1 commit into
mainfrom
03-18-apollo_propeller_wake_poll_from_on_behaviour_event
Apr 30, 2026
Merged

apollo_propeller: wake poll from on_behaviour_event#13334
sirandreww-starkware merged 1 commit into
mainfrom
03-18-apollo_propeller_wake_poll_from_on_behaviour_event

Conversation

@sirandreww-starkware

@sirandreww-starkware sirandreww-starkware commented Mar 18, 2026

Copy link
Copy Markdown
Contributor

Note

Low Risk
Small, localized change to async wakeup behavior in the connection handler; primary risk is unintended extra wakeups or missed wakeups if waker handling is incorrect.

Overview
The Propeller ConnectionHandler now caches the latest task Waker from poll and explicitly wakes it when new messages are enqueued via on_behaviour_event.

It also wakes the handler after DialUpgradeError handling (after resetting outbound state / clearing the send queue) so the connection can promptly progress without waiting for an external poll.

Written by Cursor Bugbot for commit f340c33. This will update automatically on new commits. Configure here.

@reviewable-StarkWare

Copy link
Copy Markdown

This change is Reviewable

@sirandreww-starkware sirandreww-starkware self-assigned this Mar 18, 2026

@guy-starkware guy-starkware left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@guy-starkware reviewed 1 file and all commit messages, and made 1 comment.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on ShahakShama and sirandreww-starkware).


crates/apollo_propeller/src/handler.rs line 507 at r1 (raw file):

        // Store the waker so on_behaviour_event / on_connection_event can wake us.
        // Only clone when we're actually going to sleep (Pending), and skip if unchanged.
        if result.is_pending() && !self.waker.as_ref().is_some_and(|w| w.will_wake(cx.waker())) {

I'm not going to block you on this, and honestly I don't know what you can do... but this conditional (starting with the !) is not super readable. Don't spend too much time on it though...

@ShahakShama ShahakShama left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ShahakShama reviewed all commit messages and made 1 comment.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on sirandreww-starkware).


crates/apollo_propeller/src/handler.rs line 507 at r1 (raw file):

        // Store the waker so on_behaviour_event / on_connection_event can wake us.
        // Only clone when we're actually going to sleep (Pending), and skip if unchanged.
        if result.is_pending() && !self.waker.as_ref().is_some_and(|w| w.will_wake(cx.waker())) {

What's the harm if we always store the waker? Say both to me and to the comment

@sirandreww-starkware sirandreww-starkware force-pushed the 03-18-apollo_propeller_wake_poll_from_on_behaviour_event branch from 8969808 to 8dda1ff Compare March 26, 2026 19:15
@sirandreww-starkware sirandreww-starkware force-pushed the 03-18-apollo_propeller_drain_send_queue_on_dialupgradeerror branch from 157edb8 to 8b50eb8 Compare March 26, 2026 19:15
@sirandreww-starkware sirandreww-starkware changed the base branch from 03-18-apollo_propeller_drain_send_queue_on_dialupgradeerror to graphite-base/13334 March 26, 2026 19:34
@sirandreww-starkware sirandreww-starkware force-pushed the 03-18-apollo_propeller_wake_poll_from_on_behaviour_event branch from 8dda1ff to e58cba4 Compare March 29, 2026 10:51
@sirandreww-starkware sirandreww-starkware changed the base branch from graphite-base/13334 to 03-18-apollo_propeller_drain_send_queue_on_dialupgradeerror March 29, 2026 10:51
@sirandreww-starkware sirandreww-starkware force-pushed the 03-18-apollo_propeller_wake_poll_from_on_behaviour_event branch from e58cba4 to 82f7eb8 Compare March 29, 2026 14:54
@sirandreww-starkware sirandreww-starkware force-pushed the 03-18-apollo_propeller_drain_send_queue_on_dialupgradeerror branch from 72c2036 to 098fdef Compare March 29, 2026 14:54
@sirandreww-starkware sirandreww-starkware force-pushed the 03-18-apollo_propeller_wake_poll_from_on_behaviour_event branch from 82f7eb8 to f340c33 Compare March 30, 2026 11:08
@sirandreww-starkware sirandreww-starkware force-pushed the 03-18-apollo_propeller_wake_poll_from_on_behaviour_event branch from f340c33 to c6fe4d2 Compare April 30, 2026 07:00
@sirandreww-starkware sirandreww-starkware force-pushed the 03-18-apollo_propeller_drain_send_queue_on_dialupgradeerror branch from ba9df14 to d947c62 Compare April 30, 2026 07:00
@cursor

cursor Bot commented Apr 30, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Touches async wakeup/polling behavior in a libp2p ConnectionHandler; incorrect waker usage could cause missed wakeups or extra churn, though the change is small and localized.

Overview
Improves Propeller connection-handler liveness by storing the most recent task Waker from ConnectionHandler::poll and using it to wake the handler when on_behaviour_event enqueues a new SendUnit.

Also wakes the handler after DialUpgradeError handling resets outbound state/clears the send queue, so the handler promptly re-polls to emit queued error events or re-establish an outbound substream.

Reviewed by Cursor Bugbot for commit 8b47ad3. Bugbot is set up for automated code reviews on this repo. Configure here.

@sirandreww-starkware sirandreww-starkware force-pushed the 03-18-apollo_propeller_wake_poll_from_on_behaviour_event branch from c6fe4d2 to f597519 Compare April 30, 2026 07:17

@sirandreww-starkware sirandreww-starkware left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sirandreww-starkware made 2 comments.
Reviewable status: 0 of 1 files reviewed, 2 unresolved discussions (waiting on guy-starkware and ShahakShama).


crates/apollo_propeller/src/handler.rs line 507 at r1 (raw file):

Previously, guy-starkware wrote…

I'm not going to block you on this, and honestly I don't know what you can do... but this conditional (starting with the !) is not super readable. Don't spend too much time on it though...

Simplified — now always store the waker, dropping the conditional entirely. Wakers are cheap Arc clones, so the optimization wasn't worth the readability cost.


crates/apollo_propeller/src/handler.rs line 507 at r1 (raw file):

Previously, ShahakShama wrote…

What's the harm if we always store the waker? Say both to me and to the comment

No harm — Waker is Arc-backed so clone() is just a refcount bump. Switched to unconditionally storing the waker and trimmed the comment to match.

@ShahakShama ShahakShama left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

@ShahakShama reviewed 1 file and all commit messages, made 2 comments, and resolved 1 discussion.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on guy-starkware, ShahakShama, and sirandreww-starkware).


crates/apollo_propeller/src/handler.rs line 76 at r2 (raw file):

    /// Maximum wire message size for batching.
    max_wire_message_size: usize,
    /// The most recent waker from [`ConnectionHandler::poll`], used to wake the task when new

used to sounds like it used to but it isn't now
I think used for waking is the best but maybe there are other better options

@sirandreww-starkware sirandreww-starkware changed the base branch from 03-18-apollo_propeller_drain_send_queue_on_dialupgradeerror to main April 30, 2026 08:57
@sirandreww-starkware sirandreww-starkware force-pushed the 03-18-apollo_propeller_wake_poll_from_on_behaviour_event branch from f597519 to 1eb7249 Compare April 30, 2026 08:58
@graphite-app

graphite-app Bot commented Apr 30, 2026

Copy link
Copy Markdown

Merge activity

  • Apr 30, 8:58 AM UTC: Graphite rebased this pull request, because this pull request is set to merge when ready.

@sirandreww-starkware sirandreww-starkware force-pushed the 03-18-apollo_propeller_wake_poll_from_on_behaviour_event branch from 1eb7249 to b55aebe Compare April 30, 2026 09:05
@sirandreww-starkware sirandreww-starkware force-pushed the 03-18-apollo_propeller_wake_poll_from_on_behaviour_event branch from b55aebe to 8b47ad3 Compare April 30, 2026 09:45

@sirandreww-starkware sirandreww-starkware left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sirandreww-starkware reviewed 1 file and all commit messages, and resolved 2 discussions.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on sirandreww-starkware).

@sirandreww-starkware sirandreww-starkware added this pull request to the merge queue Apr 30, 2026
Merged via the queue into main with commit af38442 Apr 30, 2026
18 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators May 2, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants