Skip to content

Commit

Permalink
Remove cache individual PUT size limit
Browse files Browse the repository at this point in the history
The total PUT size limit for a worker request continues to apply.
  • Loading branch information
fhanau committed Mar 1, 2024
1 parent a2e1593 commit 545a39d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/workerd/io/io-context.c++
Original file line number Diff line number Diff line change
Expand Up @@ -1231,8 +1231,10 @@ private:
jsg::Promise<kj::Maybe<IoOwn<kj::AsyncInputStream>>> IoContext::makeCachePutStream(
jsg::Lock& js, kj::Own<kj::AsyncInputStream> stream) {
KJ_IF_SOME(length, stream->tryGetLength()) {
if (length > MAX_INDIVIDUAL_PUT_SIZE) {
// This Cache API subrequest would exceed the individual PUT quota.
// This Cache API subrequest would exceed the total PUT quota. There used to be a limit on
// individual puts, but now this is only used as a fast path for rejecting PUTs going beyond the
// total quota early.
if (length > MAX_TOTAL_PUT_SIZE) {
return js.resolvedPromise(kj::Maybe<IoOwn<kj::AsyncInputStream>>(kj::none));
}
}
Expand All @@ -1253,7 +1255,7 @@ jsg::Promise<kj::Maybe<IoOwn<kj::AsyncInputStream>>> IoContext::makeCachePutStre
KJ_IF_SOME(length, stream->tryGetLength()) {
// PUT with Content-Length. We rely on kj-http to enforce that the expected length is
// respected, and can just return the new quota immediately, allowing the next PUT to start.
KJ_DASSERT(length <= MAX_INDIVIDUAL_PUT_SIZE);
KJ_DASSERT(length <= MAX_TOTAL_PUT_SIZE);
KJ_DEFER(fulfiller->fulfill(kj::cp(quota)));
if (quota >= length) {
quota -= length;
Expand All @@ -1268,7 +1270,7 @@ jsg::Promise<kj::Maybe<IoOwn<kj::AsyncInputStream>>> IoContext::makeCachePutStre
// unblocks the next PUT, only after this one is complete.
//
// Note that a single chunked PUT could still blow our quota by a long shot: a script could
// make a number of PUTs totalling 499MB, then send a chunked PUT with an infinite body. It's
// make a number of PUTs totalling 4.9GB, then send a chunked PUT with an infinite body. It's
// up to the cache to stop reading from the stream in this case, but at the very least we
// will refuse to allow the initiation of any further PUT requests.
return kj::heap<CacheQuotaInputStream>(kj::mv(stream), quota, kj::mv(fulfiller));
Expand Down
1 change: 0 additions & 1 deletion src/workerd/io/io-context.h
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,6 @@ class IoContext final: public kj::Refcounted, private kj::TaskSet::ErrorHandler

constexpr static size_t GB = 1 << 30;
constexpr static size_t MAX_TOTAL_PUT_SIZE = 5 * GB;
constexpr static size_t MAX_INDIVIDUAL_PUT_SIZE = 5 * GB;
kj::Promise<size_t> cachePutQuota = MAX_TOTAL_PUT_SIZE;

kj::TaskSet waitUntilTasks;
Expand Down

0 comments on commit 545a39d

Please sign in to comment.