Skip to content

Commit

Permalink
Upper bound on socket buffer sizes.
Browse files Browse the repository at this point in the history
  • Loading branch information
zyro committed Apr 29, 2020
1 parent 9e63af3 commit 52ad3d3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr
### Added
- Print a log message when all authoritative messages have stopped during graceful shutdown.

### Changed
- Upper bound on socket buffer sizes. Flush buffer more than once per message if payload size exceeds buffer size.

## [2.11.1] - 2020-03-29
### Changed
- Update protobuf (1.3.5), websocket (1.4.2), opencensus (0.22.3), atomic (1.6.0), zap (1.14.1) dependencies.
Expand Down
9 changes: 7 additions & 2 deletions server/socket_ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@ import (
var SocketWsStatsCtx = context.Background()

func NewSocketWsAcceptor(logger *zap.Logger, config Config, sessionRegistry SessionRegistry, matchmaker Matchmaker, tracker Tracker, runtime *Runtime, jsonpbMarshaler *jsonpb.Marshaler, jsonpbUnmarshaler *jsonpb.Unmarshaler, pipeline *Pipeline) func(http.ResponseWriter, *http.Request) {
// Select buffer size based on max message size, but cap it to 512KB total (256KB read, 256KB write).
bufferSize := 256 * 1024
if maxMessageSizeBytes := int(config.GetSocket().MaxMessageSizeBytes); maxMessageSizeBytes < bufferSize {
bufferSize = maxMessageSizeBytes
}
upgrader := &websocket.Upgrader{
ReadBufferSize: int(config.GetSocket().MaxMessageSizeBytes),
WriteBufferSize: int(config.GetSocket().MaxMessageSizeBytes),
ReadBufferSize: bufferSize,
WriteBufferSize: bufferSize,
CheckOrigin: func(r *http.Request) bool { return true },
}

Expand Down

0 comments on commit 52ad3d3

Please sign in to comment.