Skip to content

Commit f267f6b

Browse files
committed
cli: tunnels can sporadically become unresponsive
Last iteration I moved some RPC logic to use Tokios "codecs" to give them cancellation safety. These operate on streams of input data. While this worked at first, I failed to take into account that the byte buffer we read from the stream could have _more_ data than just the current message under load scenarios. We were discarding any extra data from the subsequent message. In most cases caused the next message "length" to be read from the middle of the next message, which usually (when parsed as a u32) was some number of gigabytes, then causing the connection to stall forever. Fixes #181284
1 parent c74c003 commit f267f6b

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

cli/src/msgpack_rpc.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
use bytes::Buf;
67
use tokio::{
78
io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, BufReader},
89
pin,
@@ -124,8 +125,8 @@ impl tokio_util::codec::Decoder for U32PrefixedCodec {
124125
return Ok(None);
125126
}
126127

127-
let msg = src[U32_SIZE..].to_vec();
128-
src.resize(0, 0);
128+
let msg = src[U32_SIZE..required_len].to_vec();
129+
src.advance(required_len);
129130
Ok(Some(msg))
130131
}
131132
}

0 commit comments

Comments
 (0)