Merged
Conversation
tomas
reviewed
Nov 19, 2025
Owner
|
Regardless of the test, does this fix handle the scenario described in the issue? |
Contributor
Author
Absolutely. Here is how I verified: With the fix: cklein@minitrueee:~/elastisys/needle$ git log -1
commit a52baad790cf6174bc3aa0349425bd4fcb8677e6 (HEAD -> fix-redirect-with-head-with-body, origin/fix-redirect-with-head-with-body)
Author: Cristian Klein <cristian.klein@elastisys.com>
Date: Wed Nov 19 18:36:22 2025 +0100
Rename to unlisten_errors
cklein@minitrueee:~/elastisys/needle$ npx mocha test/redirect_with_bad_redirector.js
redirects with bad redirector
✓ calls back exactly once
✓ calls back exactly once with follow_keep_method
2 passing (35ms)Without the fix: cklein@minitrueee:~/elastisys/needle$ git diff
diff --git a/lib/needle.js b/lib/needle.js
index 9a116a4..fd462d3 100644
--- a/lib/needle.js
+++ b/lib/needle.js
@@ -564,7 +564,7 @@ Needle.prototype.send_request = function(count, method, uri, config, post_data,
var redirect_url = utils.resolve_url(headers.location, uri);
debug('Redirecting to ' + redirect_url.toString());
- unlisten_errors();
+ //unlisten_errors();
return self.send_request(++count, method, redirect_url.toString(), config, post_data, out, callback);
} else if (config.follow_max > 0) {
return done(new Error('Max redirects reached. Possible loop in: ' + headers.location));
cklein@minitrueee:~/elastisys/needle$ npx mocha test/redirect_with_bad_redirector.js
redirects with bad redirector
✓ calls back exactly once
1) calls back exactly once
✓ calls back exactly once with follow_keep_method
2) calls back exactly once with follow_keep_method
2 passing (41ms)
2 failing
1) redirects with bad redirector
calls back exactly once:
Error: done() called multiple times
at /home/cklein/elastisys/needle/test/redirect_with_bad_redirector.js:49:7
at done (lib/needle.js:479:14)
at PassThrough.<anonymous> (lib/needle.js:740:9)
at PassThrough.emit (node:events:531:35)
at endReadableNT (node:internal/streams/readable:1698:12)
at process.processTicksAndRejections (node:internal/process/task_queues:90:21)
2) redirects with bad redirector
calls back exactly once with follow_keep_method:
Error: done() called multiple times
at /home/cklein/elastisys/needle/test/redirect_with_bad_redirector.js:62:7
at done (lib/needle.js:479:14)
at PassThrough.<anonymous> (lib/needle.js:740:9)
at PassThrough.emit (node:events:531:35)
at endReadableNT (node:internal/streams/readable:1698:12)
at process.processTicksAndRejections (node:internal/process/task_queues:90:21)
Does this help confirm that the fix works as intended? |
Owner
|
Yup, perfect. I'll go ahead and merge. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@tomas Unsure if this is the right fix, but
npx mocha test/redirect_with_bad_redirector.jspasses. It could be that some more stuff needs to be cleared before sending the second request. Perhapsdone()needs something like apartialparameters, so it does most of the cleanup, except callingcallback.