Skip to content

Commit

Permalink
Merge pull request #3159 from cloudflare/jsnell/fixup-transformstream…
Browse files Browse the repository at this point in the history
…-backpressure
  • Loading branch information
jasnell authored Nov 23, 2024
2 parents a23e95c + 6b58166 commit cd2f9da
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/workerd/api/streams/standard.c++
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "readable.h"
#include "writable.h"

#include <workerd/io/features.h>
#include <workerd/jsg/jsg.h>
#include <workerd/util/weak-refs.h>

Expand Down Expand Up @@ -3634,6 +3635,13 @@ void TransformStreamDefaultController::enqueue(jsg::Lock& js, v8::Local<v8::Valu
bool newBackpressure = readableController.hasBackpressure();
if (newBackpressure != backpressure) {
KJ_ASSERT(newBackpressure);
// Unfortunately the original implementation forgot to actually set the backpressure
// here so the backpressure signaling failed to work correctly. This is unfortunate
// because applying the backpressure here could break existing code, so we need to
// put the fix behind a compat flag. Doh!
if (FeatureFlags::get(js).getFixupTransformStreamBackpressure()) {
setBackpressure(js, true);
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/workerd/io/compatibility-date.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -660,4 +660,12 @@ struct CompatibilityFlags @0x8f8c1b68151b6cef {
# When enabled, use of top-level await syntax in require() calls will be disallowed.
# The ecosystem and runtimes are moving to a state where top level await in modules
# is being strongly discouraged.

fixupTransformStreamBackpressure @68 :Bool
$compatEnableFlag("fixup-transform-stream-backpressure")
$compatDisableFlag("original-transform-stream-backpressure")
$compatEnableDate("2024-12-16");
# A bug in the original implementation of TransformStream failed to apply backpressure
# correctly. The fix, however, can break existing implementations that don't account
# for the bug so we need to put the fix behind a compat flag.
}

0 comments on commit cd2f9da

Please sign in to comment.