Skip to content

Commit

Permalink
Revert "websocket: Don't limit message sizes in the websocket reader (#…
Browse files Browse the repository at this point in the history
…2193)"

This reverts commit 2fe6600.
  • Loading branch information
marten-seemann committed May 9, 2023
1 parent affdf99 commit 2f22ea7
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 74 deletions.
66 changes: 0 additions & 66 deletions p2p/test/websocket/websocket_test.go

This file was deleted.

1 change: 1 addition & 0 deletions p2p/transport/websocket/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func (c conn) Read(b []byte) (int, error) {
if err == nil && n == 0 && c.readAttempts < maxReadAttempts {
c.readAttempts++
// Nothing happened, let's read again. We reached the end of the frame
// we have
// (https://github.com/nhooyr/websocket/blob/master/netconn.go#L118).
// The next read will block until we get
// the next frame. We limit here to avoid looping in case of a bunch of
Expand Down
5 changes: 0 additions & 5 deletions p2p/transport/websocket/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"crypto/tls"
"fmt"
"math"
"net"
"net/http"
"net/url"
Expand Down Expand Up @@ -110,10 +109,6 @@ func (l *listener) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}

// Set an arbitrarily large read limit since we don't actually want to limit the message size here.
// See https://github.com/nhooyr/websocket/issues/382 for details.
c.SetReadLimit(math.MaxInt64 - 1) // -1 because the library adds a byte for the fin frame

select {
case l.incoming <- conn{
Conn: ws.NetConn(context.Background(), c, ws.MessageBinary),
Expand Down
3 changes: 0 additions & 3 deletions p2p/transport/websocket/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"crypto/tls"
"fmt"
"math"
"net"
"net/http"
"net/url"
Expand Down Expand Up @@ -251,8 +250,6 @@ func (t *WebsocketTransport) maDial(ctx context.Context, raddr ma.Multiaddr) (ma
return nil, fmt.Errorf("failed to get local address")
}

// Set an arbitrarily large read limit since we don't actually want to limit the message size here.
wscon.SetReadLimit(math.MaxInt64 - 1) // -1 because the library adds a byte for the fin frame
mnc, err := manet.WrapNetConn(
conn{
Conn: ws.NetConn(context.Background(), wscon, ws.MessageBinary),
Expand Down

0 comments on commit 2f22ea7

Please sign in to comment.