Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lnrpc: increase max message size for ws proxy #7991

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/release-notes/release-notes-0.17.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,11 @@ None

* The [WalletBalance](https://github.com/lightningnetwork/lnd/pull/7857) RPC
(lncli walletbalance) now supports showing the balance for a specific account.

* The [websockets proxy now uses a larger default max
message](https://github.com/lightningnetwork/lnd/pull/7991) size to support
proxying larger messages.


## lncli Updates
* Added ability to use [environment variables to override `lncli` global
Expand Down
16 changes: 15 additions & 1 deletion lnrpc/websocket_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ const (
// an arbitrary non-empty message that has no deeper meaning but should
// be sent back by the client in the pong message.
PingContent = "are you there?"

// MaxWsMsgSize is the largest websockets message we'll attempt to
// decode in the gRPC <-> WS proxy. gRPC has a similar setting used
// elsewhere.
MaxWsMsgSize = 4 * 1024 * 1024
)

var (
Expand Down Expand Up @@ -413,9 +418,18 @@ func (r *requestForwardingReader) CloseWriter() {
// what's written to it and presents it through a bufio.Scanner interface.
func newResponseForwardingWriter() *responseForwardingWriter {
r, w := io.Pipe()

scanner := bufio.NewScanner(r)

// We pass in a custom buffer for the bufio scanner to use. We'll keep
// with a normal 64KB buffer, but allow a larger max message size,
// which may cause buffer expansion when needed.
buf := make([]byte, 0, bufio.MaxScanTokenSize)
scanner.Buffer(buf, MaxWsMsgSize)

return &responseForwardingWriter{
Writer: w,
Scanner: bufio.NewScanner(r),
Scanner: scanner,
pipeR: r,
pipeW: w,
header: http.Header{},
Expand Down