Skip to content

Commit

Permalink
pubsub: Fix broken abortion of outstanding requests
Browse files Browse the repository at this point in the history
This restores the fix from googleapis#1105
which was broken after googleapis#1070
  • Loading branch information
ctavan committed Feb 3, 2017
1 parent 7a08cec commit 2d6a54d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
4 changes: 3 additions & 1 deletion packages/common-grpc/src/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,9 @@ GrpcService.prototype.request = function(protoOpts, reqOpts, callback) {
}
};

retryRequest(null, retryOpts, function(err, resp) {
// Return the request object to allow abort()-ing long-running requests (e.g.
// pub/sub pulls)
return retryRequest(null, retryOpts, function(err, resp) {
if (!err && resp === respError) {
err = respError;
resp = null;
Expand Down
12 changes: 12 additions & 0 deletions packages/common-grpc/test/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,18 @@ describe('GrpcService', function() {
delete global.GCLOUD_SANDBOX_ENV;
});

it('should return request object with abort() method', function(done) {
grpcService.protos.Service = {
service: function() {
setImmediate(done);
return new ProtoService();
}
};

var request = grpcService.request(PROTO_OPTS, REQ_OPTS, assert.ifError);
assert.strictEqual(typeof request.abort, 'function');
});

it('should access the specified service proto object', function(done) {
grpcService.protos.CustomService = {
CustomService: function() {
Expand Down
4 changes: 2 additions & 2 deletions packages/pubsub/src/subscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -732,8 +732,8 @@ Subscription.prototype.listenForEvents_ = function() {
if (event === 'message' && --self.messageListeners === 0) {
self.closed = true;

if (self.activeRequest_ && self.activeRequest_.cancel) {
self.activeRequest_.cancel();
if (self.activeRequest_ && self.activeRequest_.abort) {
self.activeRequest_.abort();
}
}
});
Expand Down
4 changes: 2 additions & 2 deletions packages/pubsub/test/subscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -961,11 +961,11 @@ describe('Subscription', function() {
assert.strictEqual(subscription.closed, true);
});

it('should cancel the HTTP request when listeners removed', function(done) {
it('should abort the HTTP request when listeners removed', function(done) {
subscription.startPulling_ = util.noop;

subscription.activeRequest_ = {
cancel: done
abort: done
};

subscription.on('message', util.noop);
Expand Down

0 comments on commit 2d6a54d

Please sign in to comment.