From d94feb9fcdb5e19aa42a411a8028140f12c79f0e Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Fri, 18 Jun 2021 01:58:14 +0200 Subject: [PATCH] net/tcp: Fix panic when consuming 0 bytes at EOF --- embassy-net/src/tcp_socket.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/embassy-net/src/tcp_socket.rs b/embassy-net/src/tcp_socket.rs index def4c8176..25c8af459 100644 --- a/embassy-net/src/tcp_socket.rs +++ b/embassy-net/src/tcp_socket.rs @@ -151,6 +151,11 @@ impl<'a> AsyncBufRead for TcpSocket<'a> { } fn consume(self: Pin<&mut Self>, amt: usize) { + if amt == 0 { + // smoltcp's recv returns Finished if we're at EOF, + // even if we're "reading" 0 bytes. + return; + } self.with(|s| s.recv(|_| (amt, ()))).unwrap() } }