Skip to content

Commit

Permalink
Merge pull request #18878 from calixteman/issue18876
Browse files Browse the repository at this point in the history
Avoid exceptions in the console with ill-formed flate streams
  • Loading branch information
calixteman authored Oct 10, 2024
2 parents 233ac17 + f2f56b6 commit 5f522d1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
13 changes: 11 additions & 2 deletions src/core/flate_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,17 @@ class FlateStream extends DecodeStream {
try {
const { readable, writable } = new DecompressionStream("deflate");
const writer = writable.getWriter();
writer.write(bytes);
writer.close();
await writer.ready;

// We can't await writer.write() because it'll block until the reader
// starts which happens few lines below.
writer
.write(bytes)
.then(async () => {
await writer.ready;
await writer.close();
})
.catch(() => {});

const chunks = [];
let totalLength = 0;
Expand Down
10 changes: 8 additions & 2 deletions src/core/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,14 @@ async function writeStream(stream, buffer, transform) {
try {
const cs = new CompressionStream("deflate");
const writer = cs.writable.getWriter();
writer.write(bytes);
writer.close();
await writer.ready;
writer
.write(bytes)
.then(async () => {
await writer.ready;
await writer.close();
})
.catch(() => {});

// Response::text doesn't return the correct data.
const buf = await new Response(cs.readable).arrayBuffer();
Expand Down

0 comments on commit 5f522d1

Please sign in to comment.