Fix incorrect waker update condition (#7656)

This bug was first found and partially fixed by @VolodymyrBg in #7317 - this PR applies the same fix everywhere else.

The old logic updated the waker when it already matched the context, and did nothing when it was stale:

```rust
if waker.will_wake(cx.waker()) {
self.waker = Some(cx.waker().clone());
}
```

This is the wrong way around. We only want to update the waker if it doesn't match the current context:

```rust
if !waker.will_wake(cx.waker()) {
self.waker = Some(cx.waker().clone());
}
```

I don't think we've ever noticed any issues, but it’s a subtle bug that could lead to missed wakeups.
This commit is contained in:
Jimmy Chen
2025-06-28 05:01:46 +10:00
committed by GitHub
parent 83cad25d98
commit 522e00f48d
4 changed files with 4 additions and 4 deletions

View File

@@ -377,7 +377,7 @@ where
ConnectionHandlerEvent<Self::OutboundProtocol, Self::OutboundOpenInfo, Self::ToBehaviour>,
> {
if let Some(waker) = &self.waker {
if waker.will_wake(cx.waker()) {
if !waker.will_wake(cx.waker()) {
self.waker = Some(cx.waker().clone());
}
} else {

View File

@@ -600,7 +600,7 @@ impl<T: BeaconChainTypes> Stream for AttestationService<T> {
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
// Update the waker if needed.
if let Some(waker) = &self.waker {
if waker.will_wake(cx.waker()) {
if !waker.will_wake(cx.waker()) {
self.waker = Some(cx.waker().clone());
}
} else {

View File

@@ -663,7 +663,7 @@ impl<T: BeaconChainTypes> Stream for SubnetService<T> {
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
// Update the waker if needed.
if let Some(waker) = &self.waker {
if waker.will_wake(cx.waker()) {
if !waker.will_wake(cx.waker()) {
self.waker = Some(cx.waker().clone());
}
} else {

View File

@@ -319,7 +319,7 @@ impl<T: BeaconChainTypes> Stream for SyncCommitteeService<T> {
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
// update the waker if needed
if let Some(waker) = &self.waker {
if waker.will_wake(cx.waker()) {
if !waker.will_wake(cx.waker()) {
self.waker = Some(cx.waker().clone());
}
} else {