Merge pull request #7991 from Roasbeef/ws-bufio-max-msg

lnrpc: increase max message size for ws proxy
This commit is contained in:
Olaoluwa Osuntokun 2023-09-18 11:33:02 -07:00 committed by GitHub
commit 327b0c92bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View File

@ -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

View File

@ -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 (
@ -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{},