https://www.postgresql.org/docs/current/protocol-flow.html#PROTOCOL-FLOW-CANCELING-REQUESTS describes that cancel protocol has different flow that standard connection ie. it sends CancelRequest instead StartupMessage, so no protocol_negotiation on startup is called and default protocol (3.2) is applied.
As result all cancel_request in CancelHandler.on_cancel_request come as SecretKey::Bytes. This bring some inconsistency when on startup we can use protocol 3.0 SecretKey::I32, but in CancelHandler.on_cancel_request always get protocol 3.2 SecretKey::Bytes, so without additional normalization secret_key in startup and on_cancel_request will not match.
As I understand pgwire has no decision about CancelRequest decoding, and it fully rely what client send.
Potentially there are no reason to have SecretKey enum at all and always use bytes for secret_key.
pub enum SecretKey {
I32(i32),
Bytes(Bytes),
}
Moreover CancelRequest protocol 3.2 looks binary compatible with 3.0:
CancelRequest (F)
Int32
Int32(80877102)
Int32
Byten
vs
CancelRequest (F)
Int32(16)
Int32(80877102)
Int32
Int32
https://www.postgresql.org/docs/current/protocol-flow.html#PROTOCOL-FLOW-CANCELING-REQUESTS describes that cancel protocol has different flow that standard connection ie. it sends
CancelRequestinsteadStartupMessage, so noprotocol_negotiationon startup is called and default protocol (3.2) is applied.As result all
cancel_requestinCancelHandler.on_cancel_requestcome asSecretKey::Bytes. This bring some inconsistency when on startup we can use protocol 3.0SecretKey::I32, but inCancelHandler.on_cancel_requestalways get protocol 3.2SecretKey::Bytes, so without additional normalizationsecret_keyin startup and on_cancel_request will not match.As I understand pgwire has no decision about
CancelRequestdecoding, and it fully rely what client send.Potentially there are no reason to have
SecretKeyenum at all and always use bytes forsecret_key.Moreover
CancelRequestprotocol 3.2 looks binary compatible with 3.0:vs