Comments (5)
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.
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.
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.
Thanks for reporting!
Did you get the chance to debug it? I think the
fastifyHttpProxy
is waiting for thecontent-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.
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)
- Support load balancing across multiple base urls.
- Suggestion: rewriteHeaders should take originalReq as argument HOT 2
- Request type in onResponse option HOT 3
- Allow disabling request logging HOT 4
- Docs (potentially code) and Typescript definition not in sync HOT 2
- [Undici] Stream body support HOT 3
- ChainAlert: npm package release (6.7.0) has no matching tag in this repo
- Rewrite body HOT 4
- make use of global agent
- Header encoding changes, leading to `ERR_INVALID_CHAR` HOT 16
- Host and other request headers are incorrectly modified on the original request, not just the forwarded request HOT 3
- retriesCount not defined in interface FastifyReplyFromHooks HOT 2
- Option to disable request timeout HOT 2
- FastifyError [FST_REPLY_FROM_INTERNAL_SERVER_ERROR]: Connect Timeout Error HOT 4
- Odd behaviour in unit tests in disable-request-logging.test.js
- support pool for http2Requests HOT 3
- Update Documentation for multipart and reply-from interaction HOT 2
- Undici Body Timeout Error crashes fastify server HOT 5
- onResponse res instead of res.stream HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fastify-reply-from.