Skip to content

Commit 0306fa4

Browse files
committed
TCP tun poll_* may wake the same task when replacing waker
1 parent 58c78e0 commit 0306fa4

File tree

1 file changed

+9
-3
lines changed
  • crates/shadowsocks-service/src/local/tun

1 file changed

+9
-3
lines changed

crates/shadowsocks-service/src/local/tun/tcp.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ impl AsyncRead for TcpConnection {
112112
if control.recv_buffer.is_empty() {
113113
// Nothing could be read. Wait for notify.
114114
if let Some(old_waker) = control.recv_waker.replace(cx.waker().clone()) {
115-
old_waker.wake();
115+
if !old_waker.will_wake(cx.waker()) {
116+
old_waker.wake();
117+
}
116118
}
117119

118120
return Poll::Pending;
@@ -138,7 +140,9 @@ impl AsyncWrite for TcpConnection {
138140

139141
if control.send_buffer.is_full() {
140142
if let Some(old_waker) = control.send_waker.replace(cx.waker().clone()) {
141-
old_waker.wake();
143+
if !old_waker.will_wake(cx.waker()) {
144+
old_waker.wake();
145+
}
142146
}
143147

144148
return Poll::Pending;
@@ -163,7 +167,9 @@ impl AsyncWrite for TcpConnection {
163167

164168
control.is_closed = true;
165169
if let Some(old_waker) = control.send_waker.replace(cx.waker().clone()) {
166-
old_waker.wake();
170+
if !old_waker.will_wake(cx.waker()) {
171+
old_waker.wake();
172+
}
167173
}
168174

169175
Poll::Pending

0 commit comments

Comments
 (0)