|
13 | 13 | #include <workerd/io/worker.h> |
14 | 14 | #include <workerd/jsg/jsg.h> |
15 | 15 | #include <workerd/jsg/ser.h> |
| 16 | +#include <workerd/util/autogate.h> |
16 | 17 | #include <workerd/util/sentry.h> |
17 | 18 |
|
18 | 19 | #include <kj/compat/url.h> |
@@ -475,10 +476,24 @@ WebSocket::Accepted::~Accepted() noexcept(false) { |
475 | 476 | } |
476 | 477 | } |
477 | 478 |
|
| 479 | +// Default max WebSocket message size limit. Note that kj-http's own default is 1MiB |
| 480 | +// (`kj::WebSocket::SUGGESTED_MAX_MESSAGE_SIZE`). We've found this to be too small for many commmon |
| 481 | +// use cases, such as proxying Chrome Devtools Protocol messages. |
| 482 | +// |
| 483 | +// JS-RPC messages are size-limited to 32MiB, and it seems to be working well, so we're setting the |
| 484 | +// WebSocket default max message size to match that. |
| 485 | +// |
| 486 | +// TODO(soon): This is currently autogated, so that we can enable the change in production before |
| 487 | +// enabling it by default in local development. This is so that people do not inadvertently deploy |
| 488 | +// something that works locally but breaks when deployed. |
| 489 | +static constexpr size_t WEBSOCKET_MAX_MESSAGE_SIZE = 32u << 20; |
| 490 | + |
478 | 491 | void WebSocket::startReadLoop(jsg::Lock& js, kj::Maybe<kj::Own<InputGate::CriticalSection>> cs) { |
479 | 492 | size_t maxMessageSize = kj::WebSocket::SUGGESTED_MAX_MESSAGE_SIZE; |
480 | 493 | if (FeatureFlags::get(js).getIncreaseWebsocketMessageSize()) { |
481 | 494 | maxMessageSize = 128u << 20; |
| 495 | + } else if (util::Autogate::isEnabled(util::AutogateKey::WEBSOCKET_MAX_MESSAGE_SIZE_32M)) { |
| 496 | + maxMessageSize = WEBSOCKET_MAX_MESSAGE_SIZE; |
482 | 497 | } |
483 | 498 |
|
484 | 499 | // If the kj::WebSocket happens to be an AbortableWebSocket (see util/abortable.h), then |
|
0 commit comments