Skip to content

Remove unnecessary (and incorrect) &mut cast in net-tokio#4691

Merged
TheBlueMatt merged 1 commit into
lightningdevkit:mainfrom
TheBlueMatt:2026-06-mut-aliasing
Jun 15, 2026
Merged

Remove unnecessary (and incorrect) &mut cast in net-tokio#4691
TheBlueMatt merged 1 commit into
lightningdevkit:mainfrom
TheBlueMatt:2026-06-mut-aliasing

Conversation

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

The owned Waker wake method assumed it had the only reference to the sender as the Waker is owned at that point, however our Wakers can be cloned, leaving multiple references to the inner Sender (held in an Arc).

Thus, the &mut cast is technically undefined behavior. However, as this patch demonstrates, its only use is in calling an &self method which derefs an internal Arc in tokio, so its highly unlikely to lead to miscompilation.

Reported by Project Loupe.

The owned `Waker` wake method assumed it had the only reference to
the sender as the `Waker` is owned at that point, however our
`Waker`s can be `clone`d, leaving multiple references to the inner
`Sender` (held in an `Arc`).

Thus, the `&mut` cast is technically undefined behavior. However,
as this patch demonstrates, its only use is in calling an `&self`
method which derefs an internal `Arc` in tokio, so its highly
unlikely to lead to miscompilation.

Reported by Project Loupe.
@ldk-reviews-bot

ldk-reviews-bot commented Jun 15, 2026

Copy link
Copy Markdown

I've assigned @valentinewallace as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@ldk-claude-review-bot

Copy link
Copy Markdown
Collaborator

The change is minimal and correct: it converts an undefined-behavior &mut aliasing cast into a shared & reference. Tokio's mpsc::Sender::try_send takes &self, so the shared reference is sufficient, and this now matches wake_socket_waker_by_ref (line 672) which already uses &*.

No issues found.

@ldk-reviews-bot

Copy link
Copy Markdown

👋 The first review has been submitted!

Do you think this PR is ready for a second reviewer? If so, click here to assign a second reviewer.

@TheBlueMatt

Copy link
Copy Markdown
Collaborator Author

Honestly not even sure this is worth backporting.

@TheBlueMatt
TheBlueMatt merged commit 9615a65 into lightningdevkit:main Jun 15, 2026
1 check 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.

4 participants