Skip to content

Commit 9e80a12

Browse files
authored
Merge pull request #22 from tmccombs/spawn-handshake-timeouts
Abort spawned tasks for SpawningHandshakes on timeout
2 parents 5c618e9 + 9693c67 commit 9e80a12

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Fixed
66

77
- Fixed compilation on non-unix environments, where tokio-net doesn't include unix sockets
8+
- `SpawningHandshakes` will abort the tasks for pending connections when the linked futures are dropped. This should allow timeouts to cause the connectionto be closed.
89

910

1011
## 0.5.0 - 2022-03-20

src/spawning_handshake.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,35 +28,33 @@ where
2828
type AcceptFuture = HandshakeJoin<T::Stream, T::Error>;
2929

3030
fn accept(&self, stream: C) -> Self::AcceptFuture {
31-
HandshakeJoin {
32-
inner: tokio::spawn(self.0.accept(stream)),
33-
}
31+
HandshakeJoin(tokio::spawn(self.0.accept(stream)))
3432
}
3533
}
3634

35+
/// Future type returned by [`SpawningHandshakeTls::accept`];
3736
#[cfg_attr(docsrs, doc(cfg(feature = "rt")))]
38-
pin_project! {
39-
/// Future type returned by [`SpawningHandshakeTls::accept`];
40-
pub struct HandshakeJoin<Stream, Error>{
41-
#[pin]
42-
inner: JoinHandle<Result<Stream, Error>>
43-
}
44-
}
37+
pub struct HandshakeJoin<Stream, Error>(JoinHandle<Result<Stream, Error>>);
4538

46-
#[cfg_attr(docsrs, doc(cfg(feature = "rt")))]
4739
impl<Stream, Error> Future for HandshakeJoin<Stream, Error> {
4840
type Output = Result<Stream, Error>;
49-
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
50-
match self.project().inner.poll(cx) {
41+
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
42+
match Pin::new(&mut self.as_mut().0).poll(cx) {
5143
Poll::Ready(Ok(v)) => Poll::Ready(v),
5244
Poll::Pending => Poll::Pending,
5345
Poll::Ready(Err(e)) => {
5446
if e.is_panic() {
5547
std::panic::resume_unwind(e.into_panic());
5648
} else {
57-
panic!("Tls handshake was aborted: {:?}", e);
49+
unreachable!("Tls handshake was aborted: {:?}", e);
5850
}
5951
}
6052
}
6153
}
6254
}
55+
56+
impl<Stream, Error> Drop for HandshakeJoin<Stream, Error> {
57+
fn drop(&mut self) {
58+
self.0.abort();
59+
}
60+
}

0 commit comments

Comments
 (0)