Skip to content

Commit

Permalink
Merge pull request #686 from share/fix-qs-closed-check
Browse files Browse the repository at this point in the history
🐛 Fix `closed` check when handling `querySubscribe()`
  • Loading branch information
alecgibson authored Oct 24, 2024
2 parents 4b8d3dc + 35f4f56 commit 14c0104
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ Agent.prototype._querySubscribe = function(queryId, collection, query, options,
}
this.backend.querySubscribe(this, collection, query, options, function(err, emitter, results, extra) {
if (err) return finish(err);
if (this.closed) return emitter.destroy();
if (agent.closed) return emitter.destroy();

agent._subscribeToQuery(emitter, queryId, collection, query);
// No results are returned when ids are passed in as an option. Instead,
Expand Down
23 changes: 23 additions & 0 deletions test/client/query-subscribe.js
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,29 @@ function commonTests(options) {
connection.get('dogs', 'fido').on('error', done).create({age: 3});
});

it('does not reply if the agent is closed before the query returns', function(done) {
var backend = this.backend;
var connection = backend.connect();
var agent = connection.agent;

backend.use('query', function(request, next) {
backend.use('reply', function() {
done(new Error('unexpected reply'));
});

expect(agent.closed).to.be.false;
agent.stream.on('close', function() {
expect(agent.closed).to.be.true;
next();
done();
});

agent.close();
});

connection.createSubscribeQuery('dogs', {});
});

describe('passing agent.custom to the DB adapter', function() {
var connection;
var expectedArg = {
Expand Down

0 comments on commit 14c0104

Please sign in to comment.