Skip to content

Commit b78d0b6

Browse files
committed
EW-9632 Increase max WebSocket message size limit to 32MiB
See code comments for rationale. This change will be deployed to the Cloudflare network via an autogate first. Then, once that stabilizes, we'll remove the autogate, making the new limit the default for both production and local development.
1 parent 34d68be commit b78d0b6

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

src/workerd/api/web-socket.c++

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <workerd/io/worker.h>
1414
#include <workerd/jsg/jsg.h>
1515
#include <workerd/jsg/ser.h>
16+
#include <workerd/util/autogate.h>
1617
#include <workerd/util/sentry.h>
1718

1819
#include <kj/compat/url.h>
@@ -475,10 +476,24 @@ WebSocket::Accepted::~Accepted() noexcept(false) {
475476
}
476477
}
477478

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+
478491
void WebSocket::startReadLoop(jsg::Lock& js, kj::Maybe<kj::Own<InputGate::CriticalSection>> cs) {
479492
size_t maxMessageSize = kj::WebSocket::SUGGESTED_MAX_MESSAGE_SIZE;
480493
if (FeatureFlags::get(js).getIncreaseWebsocketMessageSize()) {
481494
maxMessageSize = 128u << 20;
495+
} else if (util::Autogate::isEnabled(util::AutogateKey::WEBSOCKET_MAX_MESSAGE_SIZE_32M)) {
496+
maxMessageSize = WEBSOCKET_MAX_MESSAGE_SIZE;
482497
}
483498

484499
// If the kj::WebSocket happens to be an AbortableWebSocket (see util/abortable.h), then

src/workerd/util/autogate.c++

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ kj::StringPtr KJ_STRINGIFY(AutogateKey key) {
2525
return "streaming-tail-worker"_kj;
2626
case AutogateKey::TAIL_STREAM_REFACTOR:
2727
return "tail-stream-refactor"_kj;
28+
case AutogateKey::WEBSOCKET_MAX_MESSAGE_SIZE_32M:
29+
return "websocket-max-message-size-32m"_kj;
2830
case AutogateKey::NumOfKeys:
2931
KJ_FAIL_ASSERT("NumOfKeys should not be used in getName");
3032
}

src/workerd/util/autogate.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ enum class AutogateKey {
2020
STREAMING_TAIL_WORKER,
2121
// Enable refactor used to consolidate the different tail worker stream implementations.
2222
TAIL_STREAM_REFACTOR,
23+
// Increase max WebSocket message size to 32MiB.
24+
WEBSOCKET_MAX_MESSAGE_SIZE_32M,
2325
NumOfKeys // Reserved for iteration.
2426
};
2527

0 commit comments

Comments
 (0)