You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add pgconn.Config.MaxBodyLen and apply it to pgproto3.Frontend during ConnectConfig and Construct.
Add regression coverage for configured body length limits.
Rationale
pgproto3.Frontend already supports SetMaxBodyLen, but pgconn users currently need to reach through to the protocol frontend to configure it. Exposing the setting on pgconn.Config makes it possible to reject unreasonable message bodies before chunkReader allocates the buffer.
The default remains 0, so no maximum is enforced unless callers opt in. This preserves the existing behavior while allowing applications to configure a defensive limit.
Testing
go test ./pgproto3 ./pgconn -run 'TestFrontendReceiveExceededMaxBodyLen|TestBackendReceiveExceededMaxBodyLen|TestConnectConfigMaxBodyLen|TestConfigCopyReturnsEqualConfig'
carter-ya
changed the title
pgconn: expose frontend max body length
pgconn: add configurable max message body length
May 15, 2026
Is MaxBodyLen the right name for this at the pgconn.Config layer? It has a clear meaning at the pgproto3.Frontend layer. But at the connection / config layer I'm not sure I would immediately understand what it meant. 🤷
Is MaxBodyLen the right name for this at the pgconn.Config layer? It has a clear meaning at the pgproto3.Frontend layer. But at the connection / config layer I'm not sure I would immediately understand what it meant. 🤷
Good point. MaxBodyLen mirrors the pgproto3.Frontend API, but I agree it may be too protocol-internal for pgconn.Config.
Would you prefer one of these directions?
Keep it as a top-level pgconn.Config field, but use a more explicit name, e.g. MaxProtocolMessageBodyLen.
Add a small protocol namespace, e.g. Config.Protocol.MaxMessageBodyLen, so future protocol-level frontend options have a clearer home.
My current leaning is option 1 as the smallest API change, but option 2 may be cleaner if you expect more protocol-level knobs to be exposed later.
One additional bit of information: this already can be configured on connection with Config.BuildFrontend. This feature doesn't enable new functionality, it makes it a bit easier to use. Depending on how frequently this is used, it may or may not be necessary to add this helper. That said, I'm willing to accept it.
I would go for the top-level pgconn.Config field. That matches what we already have with MinProtocolVersion and MaxProtocolVersion.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
pgconn.Config.MaxBodyLenand apply it topgproto3.FrontendduringConnectConfigandConstruct.Rationale
pgproto3.Frontendalready supportsSetMaxBodyLen, butpgconnusers currently need to reach through to the protocol frontend to configure it. Exposing the setting onpgconn.Configmakes it possible to reject unreasonable message bodies beforechunkReaderallocates the buffer.The default remains
0, so no maximum is enforced unless callers opt in. This preserves the existing behavior while allowing applications to configure a defensive limit.Testing
go test ./pgproto3 ./pgconn -run 'TestFrontendReceiveExceededMaxBodyLen|TestBackendReceiveExceededMaxBodyLen|TestConnectConfigMaxBodyLen|TestConfigCopyReturnsEqualConfig'