-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
remove annoying "double callback" warning #313
Comments
it's a bug in superagent, that's why it's a warn, crashing your entire proc is definitely less ideal |
hmm.. ok. workaround? |
@visionmedia I could just change it to debug() for now. |
+1 for debug :) |
oh wait actually now i forget, i dont think it was a superagent bug, ignoring it is no good, but throwing is also no good |
@stephenmathieson this warning is implemented to avoid double callbacks and you should not be getting the warning. Without any clue as to how your implementation is triggering this warning I will not attempt to thumb suck a cause. Can you try and isolate and produce an example (in the least amount of code) which causes this warning to appear? Another related issue #290 which may provide additional clues but please don't refrain from providing the example snippet for future reference and aiding others. |
@visionmedia superagent is ignoring it. it's just returning and writing stuff to stderr. @nickl- yeah, as it's an implementation issue, it sounds like throwing is exactly what should happen.. |
@stephenmathieson can you please add a snippet/gist of the code you have that causes it? |
it should pass the error but at the time when we had this we couldn't afford crashing node processes over and over so I added a warning |
@gjohnson i don't have it anymore. i had not committed, as it was broken :p if i come across it again, i'll post it |
In absence of the much needed cause of the problem as silver lining at least we can celebrate @stephenmathieson's issue resolved \o/ Advise mark "Works as intended" and close. |
I might be doing something wrong, but I had the double callbacks warning with this: var req = request
.put(someUrl)
.set('Content-Type', contentType);
var stream = fs.createReadStream(file);
stream.pipe(req);
req.end(function(res) {....}); |
Tx @jonasfj this will definitely help to narrow it down. You rock! |
@jonasfj in that snippet you're piping to |
Yeah, it was probably just me doing it wrong... I got it working by using Anyways, this is more likely a case of me being confused by the documentation. |
no worries, streams are like that they don't really make sense in their current state |
From the code it is obvious that the double callback was prevented, the warning however raises alarm that this is a problem but we already circumvented the problem when the warning was raised. The questions that remain:
|
I'm getting the double callback message when testing (with mocha) the GET routes of my API:
None of my POST/PUT/DELETE requests are getting it and they're in the same format. What's causing it in this case? |
Why am I getting this for something as simple as piping a stream? It's basically done like in the docs, so going by the docs is causing warning? Or am I missing something? var s = http.createServer(app);
s.listen(0);
var addr = s.address();
var host = addr.address;
var port = addr.port;
var req = agent.put('http://' + host + ':' + port + '/documents/' + id).type('application/pdf');
var stream = fs.createReadStream(__dirname + '/data/sample.pdf');
stream.pipe(req);
// results in 'double callback'.... |
I am getting it also very often, we need to identify reasons and fix it finally. Probably in some cases it is ok when its double called and there is no need for the warning. Just ensure not calling users callback twice. |
Try piping the stream with options It sounds like a bug that you can just rely on end from stream... |
Getting the same entering every superagent .end() cb but this happens only when using gulp watch... Manual CLI mocha or gulp "test" (task piping gulp-mocha) work allright. Only in gulp watch mode surveying test/*.js and triggering "test" task. it('No status is provided. Returns [500: ' + errmsg.noStatus + ']', function(done) { agent.put('http://localhost:3000/api/invoice') .send(fixt.invoices.no_status) .end(function(err, res) { // double callback should.not.exist(err); res.status.should.eql(500); res.type.should.eql('text/plain'); res.text.should.eql(errmsg.noStatus); done(); }); }); --------- // gulpfile part gulp.task('test', function() { gulp.src('test/*.js') .pipe(mocha({reporter: 'spec'})); }); gulp.task('watch-test', function() { gulp.watch('test/*.js', ['test']); }); Nothing new since last comment on July ? |
Having same issue, not sure why :(. |
I also got the same issue when the remote server is down. I expect that error message should be passed via callback instead. |
Also experiencing this issue using gulp watch with mocha. var request = require('supertest'),
worker = require('../src/worker');
describe('POST /message', function() {
var app;
beforeEach(function() {
app = worker();
});
it('handles valid request', function(done) {
request(app)
.post('/message')
.send({version: 10, docId: 'blah'})
.expect(200, function(err, response) {
assert.equal(resonse.body, 'some content');
})
.end(done);
});
}); This test passes the first time every time. Then after about 3 file saves it will fail for the next few file saves, and eventually pass again intermittently going back and forth with the double callback error.
|
I may have found the root cause and a workaround. It looks like providing a callback handler to I have changed our test code to always pass a callback to Haven't seen a recurrence for an hour or so. |
I found my way here because of "double callback!" messages while running Mocha tests with Nock. I am leaving this message mostly to cross-link to more info at #417. And in Nock's issues: nock/nock#211 One small trick for checking to see if the SuperAgent-to-Nock interaction is your problem is to call nock.enableNetConnect() right before firing off a request with SuperAgent. Toggle that on and off with comments while running Mocha and you might just have found where your prey is hiding. |
I have found a workaround for my particular case. In a mocha test file, I was doing: request.post("http://127.0.0.1/")
.send(new Buffer(1024*1025))
.end(function(err, result) {
// Some asserts go here
done()
}) I changed it to var buf = new Buffer(1025*1024).toString("utf8")
request.post("http://127.0.0.1/")
.send(buf)
.end(function(err, result) {
// Some asserts go here
done()
}) and the problem disappeared |
Why is this issue closed ? Im still having problems with double callback, the following simple situation causes a double callback. It might be related to JSON.parse throwing an error further down the chain.
|
Same problem here |
I was seeing the 'double callback!' message along with a |
I had this issue again today after doing some extensive unrelated updates in my codebase. In my case the culprit turned out to be the 'faux promise support'. basically i did something like this (abbreviated):
the
this happens in ES6 with the above syntax or with e.g coffeescript or with ES5 when its the return value of my send function is interpreted as a promise thus the in the 2nd call TL;DR: had the request hooked up with 'end callback' AND '.then callback' causing double request. |
I had the same issue. The first case of the following works well but the second prints "double callback" message and the done() callback was not called so timeout error occurred. It seems that supertest inside a promise then block can easily reproduce the problem. it '# success', (done) ->
supertest(dbServerUrl)
.get('/_all_dbs')
.expect(200)
.end (err) ->
if err
done.fail(err)
else
done()
it '# failed', (done) ->
Q('5')
.then ->
supertest(dbServerUrl)
.get('/_all_dbs')
.expect(200)
.end (err) ->
if err
done.fail(err)
else
done() |
@ybian I also get the same issue when I use promises although in my case I was using bluebird. |
Superagent 2.0 fixes handling of |
As of 1.8.3 and 2.0.0-alpha1, my test case higher still outputs |
I got the |
I'm on 2.0.0-alpha3, and I'm getting double callback example code:
further info: I'm using es6 (not everywhere mind you) that's translated via babel. |
I can't reproduce this issue with any of the code posted in the thread. I suspect the double callback issue depends on specific HTTP headers and possibly timing of server response, so if you're reporting the issue, please include real, working public URLs that I can investigate. |
@pornel further information that may prove helpful, I only see these warnings when running the code through mocha. so some additional code:
running the code posted above within the test suite causes ... 3 warnings to show up.
the local api server I'm running is a vanilla django rest framework setup. no custom headers or anything. |
Same issue with 'double callback!' with version 1.8.4.
As a conclusion for some reason superagent executes callback twice with no resolving the second one which leads the process to hang up. |
We know 1.8 is buggy — we've already fixed those bugs in later versions. Especially 2.2 and later removed many double callback problems. Please upgrade. |
I was getting double callback because I had the port forwarded via nat using virtual box (boot2docker). I was running a containerized app locally and forgot the same port was used for both. Funny thing is the server starts and I am able to browse to it with no warnings. But when I run supertest, I encounter the double callback error. Once I changed the port, it worked fine. I don't consider this a problem, just posting it here for future reference. This was occurring under the latest versions (2.0.0 SA & 2.3.0 ST). |
Superagent 2.0.0 has this bug. The fix is in Superagent 2.2 or later. Supertest changes quite a lot about behavior of superagent, so if you have a bug that happens when running supertest, please report it to the supertest project. |
I can still reproduce #313 (comment) in 3.3 using Note that Could that mean that the warning is shown when there is an error between the moment the connection is established and the body is completely received ? |
Sorry, I can't reproduce this (superagent 3.3, Node 7.2 osx). Timeout is in our test suite. |
If you run into this problem, please change:
to if (this.called) return console.trace('superagent: double callback bug', this.called);
this.called = Error("previous trace"); and report the stack traces. |
The previous trace:
You need to play with the timeout values until you get the sweet spot where half of them are timeouts and half of them are success. Using a mobile network makes it very hard to reproduce. |
I cannot reproduce my use case on 3.3.1 🎉 |
Routes work based on manual testing (use postman collection at https://drive.google.com/open?id=10asLodbjwB0jMq_6NVGVKmni_P3xNL69) Integration tests seem to be failing due to a strange 'double callback' bug in superagent See Github issue here: ladjs/superagent#313 Planning to get replace supertest (the dependency using superagent) with axios or similar in next commit
i'd rather have an error thrown than
console.warn('double callback!')
The text was updated successfully, but these errors were encountered: