Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 Error in serving socket.io.min.js #4946

Closed
RutvikChandla opened this issue Feb 8, 2024 · 1 comment
Closed

馃悰 Error in serving socket.io.min.js #4946

RutvikChandla opened this issue Feb 8, 2024 · 1 comment
Labels
to triage Waiting to be triaged by a member of the team

Comments

@RutvikChandla
Copy link

Describe the bug

socket.io/lib/index.ts

Lines 625 to 643 in e36062c

switch (encoding) {
case "br":
res.writeHead(200, { "content-encoding": "br" });
readStream.pipe(createBrotliCompress()).pipe(res);
pipeline(readStream, createBrotliCompress(), res, onError);
break;
case "gzip":
res.writeHead(200, { "content-encoding": "gzip" });
pipeline(readStream, createGzip(), res, onError);
break;
case "deflate":
res.writeHead(200, { "content-encoding": "deflate" });
pipeline(readStream, createDeflate(), res, onError);
break;
default:
res.writeHead(200);
pipeline(readStream, res, onError);
}
}

While serving assets and encoding is 'br' there is a race condition, seeing code we are piping 2 times. Should be only 1 time

        readStream.pipe(createBrotliCompress()).pipe(res);
        pipeline(readStream, createBrotliCompress(), res, onError);

below is the error I'm getting below error when serving /socket.io.min.js

error Error [ERR_STREAM_PREMATURE_CLOSE]: Premature close
    at new NodeError (node:internal/errors:393:5)
    at ServerResponse.<anonymous> (node:internal/streams/pipeline:352:14)
    at ServerResponse.emit (node:events:525:35)
    at ServerResponse.emit (node:domain:489:12)
    at emitCloseNT (node:_http_server:961:10)
    at processTicksAndRejections (node:internal/process/task_queues:81:21) {
  code: 'ERR_STREAM_PREMATURE_CLOSE'
}

To Reproduce

When browser uses br as accept encoding to download files added in <script src="">
Getting the above error.

Expected behavior
A clear and concise description of what you expected to happen.

Platform:

  • Device: [e.g. Samsung S8]
  • OS: [e.g. Android 9.2]
@RutvikChandla RutvikChandla added the to triage Waiting to be triaged by a member of the team label Feb 8, 2024
@darrachequesne
Copy link
Member

Good catch, thanks!

This should be fixed by e426f3e.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
to triage Waiting to be triaged by a member of the team
Projects
None yet
Development

No branches or pull requests

2 participants