You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi
For a specific test, we need to make sure that two subsequent requests use the same connection.
So, I use forever-agent with request module and it works great if the two requests are GET.
Now if the second request is a POST, the second request is never sent and it blocks forever.
After some investigations, I see that in the pb is in 'addRequest':
in the case of POST, the code does not enter the logic to reuse socket, but calls parent method addRequestNoreuse.
The reason is the test on 'req.useChunkedEncodingByDefault', which is set to true in case of a POST.
if (this.freeSockets[name] && this.freeSockets[name].length > 0
&& !req.useChunkedEncodingByDefault) {
If I remove this test, it works fine.
So, of course I could patch the forever-agent to do what I want, but I was wondering
if there is a clean solution to this pb (apparently, we cannot set the value useChunkedEncodingByDefault ourselves on the request, it is set automatically if POST is used)
why does the agent needs to check useChunkedEncodingByDefault ?
Thanks
Yann
The text was updated successfully, but these errors were encountered:
I am experiencing a similar issue, where the check for req.useChunkedEncodingByDefault is preventing socket reuse for a persistent connection that I need for a series of POST requests.
I'm currently getting past the problem by checking req.chunkedEncoding instead. Here is the change to index.js:
@@ -48,7 +48,7 @@
ForeverAgent.prototype.addRequestNoreuse = Agent.prototype.addRequest
ForeverAgent.prototype.addRequest = function(req, host, port) {
var name = host + ':' + port
- if (this.freeSockets[name] && this.freeSockets[name].length > 0 && !req.useChunkedEncodingByDefault) {+ if (this.freeSockets[name] && this.freeSockets[name].length > 0 && !req.chunkedEncoding) {
var idleSocket = this.freeSockets[name].pop()
idleSocket.removeListener('error', idleSocket._onIdleError)
delete idleSocket._onIdleError
Hi
For a specific test, we need to make sure that two subsequent requests use the same connection.
So, I use forever-agent with request module and it works great if the two requests are GET.
Now if the second request is a POST, the second request is never sent and it blocks forever.
After some investigations, I see that in the pb is in 'addRequest':
in the case of POST, the code does not enter the logic to reuse socket, but calls parent method addRequestNoreuse.
The reason is the test on 'req.useChunkedEncodingByDefault', which is set to true in case of a POST.
If I remove this test, it works fine.
So, of course I could patch the forever-agent to do what I want, but I was wondering
Thanks
Yann
The text was updated successfully, but these errors were encountered: