Skip to content

pgconn: add configurable max message body length#2558

Open
carter-ya wants to merge 1 commit into
jackc:masterfrom
carter-ya:codex/configurable-max-body-len
Open

pgconn: add configurable max message body length#2558
carter-ya wants to merge 1 commit into
jackc:masterfrom
carter-ya:codex/configurable-max-body-len

Conversation

@carter-ya
Copy link
Copy Markdown

@carter-ya carter-ya commented May 15, 2026

Summary

  • 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 carter-ya changed the title pgconn: expose frontend max body length pgconn: add configurable max message body length May 15, 2026
@carter-ya carter-ya force-pushed the codex/configurable-max-body-len branch from c870425 to f8fca46 Compare May 15, 2026 12:08
@jackc
Copy link
Copy Markdown
Owner

jackc commented May 16, 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. 🤷

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants