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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle stream end not fired #946

Open
anton89 opened this issue Oct 11, 2023 · 2 comments
Open

How to handle stream end not fired #946

anton89 opened this issue Oct 11, 2023 · 2 comments

Comments

@anton89
Copy link

anton89 commented Oct 11, 2023

You have already researched for similar issues?

Yes

What are you trying to achieve, or the steps to reproduce?

I receive webhook from JIRA server, some of the jira webhook doesn't have stream doesn't have end or never fired end, this cause the request to hang/swallowed up, to prove this I put hooks for preParsing and preValidation both preParsing get called, but it never went through preValidation,

I tried this code

fastify.addHook('preParsing', async (request, reply, payload) => {
  console.log("🚀 ~ file: server.js:20 ~ fastify.addHook ~ preParsing:")
  const chunks = [];

  try {
    const result = await new Promise((resolve, reject) => {
      console.log('1');
      payload.on('data', (chunk) => {
        console.log('a');
        chunks.push(Buffer.from(chunk))
      });
      console.log('2');
      payload.on('error', (err) => {
        console.log('b');
        reject(err)
      });
      console.log('3');
      payload.on('end', () => {
        console.log('c'); 
        resolve(Buffer.concat(chunks).toString('utf8'))
      });

the stream end is indeed never fired

What was the result you received?

no reply, no error ever called

What did you expect?

the request can went though

Context

  • node version: 14.21.3
  • fastify version: >=4.23.2
  • os: Linux
@anton89
Copy link
Author

anton89 commented Oct 11, 2023

it is related to this https://stackoverflow.com/questions/34540095/readable-onend-is-never-fired
but I wonder how to handle this correctly

@mcollina
Copy link
Member

Thanks for reporting!

Can you provide steps to reproduce? We often need a reproducible example, e.g. some code that allows someone else to recreate your problem by just copying and pasting it. If it involves more than a couple of different file, create a new repository on GitHub and add a link to that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants