ITADN

Decode error due to invalid decode_context state

#386Opensomtochiama 创建于 2026-01-22
S
somtochiamacommented
We can run into decoding errors due to the previous state in decode context. here's a simplified code snippet to illustrate the issue: ```rust first_msg = framed.next().await?; start_msg = if first_msg.is_ssl() { framed.setState(PgWireConnectionState::AwaitingStartup) framed.next().await()? } else { first_msg } framed.setState(PgWireConnectionState::ReadyForQuery) next_msg = framed.next().await() ``` Running this fails with the error when a StartupMessage is received first. ``` Invalid message length, expected max 1342177280, actual: 10000 ``` This is because only awaiting_startup will get set to false in the decode function, but awaiting_ssl is still true so it is looking for a startup message. I am thinking that it might be better to specifically reset both `awaiting_ssl` and `awaiting_startup` in each branch of this [function](https://github.com/sunng87/pgwire/blob/adb4424b95d137b56720b42aff06f298fde53aea/src/tokio/server.rs#L52) so that there's no unintended behaviour due to previous function calls. Happy to submit a small pr if that's the case
2 条评论