Skip to content
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

🐛 Fix closed check when handling querySubscribe() #686

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading