Merge pull request #363 from episage/master
fix: prevent double callback in _executeRequest
This commit is contained in:
commit
be56cccd24
|
@ -158,8 +158,13 @@ exports.OAuth2.prototype._executeRequest= function( http_library, options, post_
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
request.on('error', function(e) {
|
request.on('error', function(e) {
|
||||||
|
// `www.googleapis.com` does `ECONNRESET` just after data is received in `passBackControl`
|
||||||
|
// this prevents the callback from being called twice, first in passBackControl and second time in here
|
||||||
|
// see also NodeJS Stream documentation: "The 'error' event may be emitted by a Readable implementation at any time"
|
||||||
|
if(!callbackCalled) {
|
||||||
callbackCalled= true;
|
callbackCalled= true;
|
||||||
callback(e);
|
callback(e);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if( (options.method == 'POST' || options.method == 'PUT') && post_body ) {
|
if( (options.method == 'POST' || options.method == 'PUT') && post_body ) {
|
||||||
|
|
Loading…
Reference in New Issue