Skip to content

Commit 522e00f

Browse files
authored
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.
1 parent 83cad25 commit 522e00f

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

beacon_node/lighthouse_network/src/rpc/handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ where
377377
ConnectionHandlerEvent<Self::OutboundProtocol, Self::OutboundOpenInfo, Self::ToBehaviour>,
378378
> {
379379
if let Some(waker) = &self.waker {
380-
if waker.will_wake(cx.waker()) {
380+
if !waker.will_wake(cx.waker()) {
381381
self.waker = Some(cx.waker().clone());
382382
}
383383
} else {

beacon_node/network/src/subnet_service/attestation_subnets.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ impl<T: BeaconChainTypes> Stream for AttestationService<T> {
600600
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
601601
// Update the waker if needed.
602602
if let Some(waker) = &self.waker {
603-
if waker.will_wake(cx.waker()) {
603+
if !waker.will_wake(cx.waker()) {
604604
self.waker = Some(cx.waker().clone());
605605
}
606606
} else {

beacon_node/network/src/subnet_service/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ impl<T: BeaconChainTypes> Stream for SubnetService<T> {
663663
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
664664
// Update the waker if needed.
665665
if let Some(waker) = &self.waker {
666-
if waker.will_wake(cx.waker()) {
666+
if !waker.will_wake(cx.waker()) {
667667
self.waker = Some(cx.waker().clone());
668668
}
669669
} else {

beacon_node/network/src/subnet_service/sync_subnets.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ impl<T: BeaconChainTypes> Stream for SyncCommitteeService<T> {
319319
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
320320
// update the waker if needed
321321
if let Some(waker) = &self.waker {
322-
if waker.will_wake(cx.waker()) {
322+
if !waker.will_wake(cx.waker()) {
323323
self.waker = Some(cx.waker().clone());
324324
}
325325
} else {

0 commit comments

Comments
 (0)