Giter Site home page Giter Site logo

Comments (5)

szegheo avatar szegheo commented on June 8, 2024

OK, finally I figured out, that it occurs when the client request arrives with Connection: keep-alive (default on HTTP/1.1 requests). Run the code below and wait ~3 sec:

const Fastify = require('fastify')
const fastifyHttpProxy = require('@fastify/http-proxy')

// PROXY TARGET
const fastifyProxyTarget = Fastify({
  logger: { level: 'debug' },
  disableRequestLogging: false,
}).put('/api', async (request, reply) => reply.code(204).send())

// CLIENT REQUESTS RECEIVER
const fastify = Fastify({
  logger: { level: 'debug' },
  disableRequestLogging: false,
});

fastify.register(fastifyHttpProxy, {
  upstream: 'http://localhost:3000/',
  prefix: '/proxytest',
  http2: false,
  http: {
    requestOptions: {
      timeout: 2000 //2sec
    }
  }
});

async function startTest() {
  await fastifyProxyTarget.listen({ port: 3000 });
  await fastify.listen({ port: 5000 });

  await fetch('http://localhost:5000/proxytest/api', {
    method: 'PUT',
    headers: {
      // 'Connection': 'close' // OK
      'Connection': 'keep-alive' // response errored
    }
  });
}

startTest()

The above code triggers the "response errored" warning with (current) v4.25.1, but not with 4.23.2

from fastify-reply-from.

szegheo avatar szegheo commented on June 8, 2024

Testing it further, it's now clear that it happens when the response code is 204 (method independent) and only with Node's http request (proxy options).

from fastify-reply-from.

Eomm avatar Eomm commented on June 8, 2024

Thanks for reporting!

Did you get the chance to debug it?
I think the fastifyHttpProxy is waiting for the content-length IMHO, but I'm only guessing

from fastify-reply-from.

szegheo avatar szegheo commented on June 8, 2024

Thanks for reporting!

Did you get the chance to debug it? I think the fastifyHttpProxy is waiting for the content-length IMHO, but I'm only guessing

Ok, I'll try to look into it deeper, but unfortunately I'm not a Fastify expert (doing FE things mostly)

from fastify-reply-from.

szegheo avatar szegheo commented on June 8, 2024

From the side of Fastify, it seems quite clear, that this issue was brought in with this change.
Currently, that new if block runs here because of the statusCode 204, and then it returns.
When I skip that if block, the issue is gone.
When I copy the next sendStream block into this new block, the issue is gone too.

Looking at the code of fastify-reply-from, the timeout error (that I reported) is created by handleHttp1Req, so maybe there should be some new check here to decide if the error should be forwarded or not.

The original timeout event is coming from Node's http module:

Emitted when the underlying socket times out from inactivity. This only notifies that the socket has been idle. The request must be destroyed manually.

Unfortunately, I do not have the necessary (deep) http knowledge to create a proper fix, but I hope at least these information will somehow useful. Honestly, I also wondering if the fix should be done here in reply-from or in Fastify (or both).

Thank you!

from fastify-reply-from.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.