fix: prevent double callback in _executeRequest

This commit is contained in:
Tomasz Ciborski 2021-11-16 11:05:40 +01:00
parent a7f8a1e21c
commit db8088793f
No known key found for this signature in database
GPG Key ID: E40FF45956926CF0
1 changed files with 7 additions and 2 deletions

View File

@ -158,8 +158,13 @@ exports.OAuth2.prototype._executeRequest= function( http_library, options, post_
});
});
request.on('error', function(e) {
callbackCalled= true;
callback(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;
callback(e);
}
});
if( (options.method == 'POST' || options.method == 'PUT') && post_body ) {