mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-20 05:14:35 +00:00
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:
@@ -377,7 +377,7 @@ where
|
|||||||
ConnectionHandlerEvent<Self::OutboundProtocol, Self::OutboundOpenInfo, Self::ToBehaviour>,
|
ConnectionHandlerEvent<Self::OutboundProtocol, Self::OutboundOpenInfo, Self::ToBehaviour>,
|
||||||
> {
|
> {
|
||||||
if let Some(waker) = &self.waker {
|
if let Some(waker) = &self.waker {
|
||||||
if waker.will_wake(cx.waker()) {
|
if !waker.will_wake(cx.waker()) {
|
||||||
self.waker = Some(cx.waker().clone());
|
self.waker = Some(cx.waker().clone());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -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>> {
|
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
||||||
// Update the waker if needed.
|
// Update the waker if needed.
|
||||||
if let Some(waker) = &self.waker {
|
if let Some(waker) = &self.waker {
|
||||||
if waker.will_wake(cx.waker()) {
|
if !waker.will_wake(cx.waker()) {
|
||||||
self.waker = Some(cx.waker().clone());
|
self.waker = Some(cx.waker().clone());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -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>> {
|
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
||||||
// Update the waker if needed.
|
// Update the waker if needed.
|
||||||
if let Some(waker) = &self.waker {
|
if let Some(waker) = &self.waker {
|
||||||
if waker.will_wake(cx.waker()) {
|
if !waker.will_wake(cx.waker()) {
|
||||||
self.waker = Some(cx.waker().clone());
|
self.waker = Some(cx.waker().clone());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -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>> {
|
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
||||||
// update the waker if needed
|
// update the waker if needed
|
||||||
if let Some(waker) = &self.waker {
|
if let Some(waker) = &self.waker {
|
||||||
if waker.will_wake(cx.waker()) {
|
if !waker.will_wake(cx.waker()) {
|
||||||
self.waker = Some(cx.waker().clone());
|
self.waker = Some(cx.waker().clone());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user