Skip to content

Commit

Permalink
Prevent destroy subscription if connection is draining or closed (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
kenguru33 authored Mar 9, 2023
1 parent 6b0a438 commit ab73147
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/nestjs-nats-jetstream-transport/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,12 @@ export class NatsJetStreamServer
}
})();
done.then(() => {
// if the connection is closed or draining, we don't need to unsubscribe as the subscription will be unsubscribed automatically
if (this.nc.isDraining() || this.nc.isClosed()) {
return;
}
subscription.destroy();

this.logger.log(`Unsubscribed ${subject}`);
});
}
Expand Down Expand Up @@ -122,7 +127,10 @@ export class NatsJetStreamServer
);

if (stream) {
const streamSubjects = new Set([...stream.config.subjects, ...streamConfig.subjects]);
const streamSubjects = new Set([
...stream.config.subjects,
...streamConfig.subjects,
]);

const streamInfo = await this.jsm.streams.update(stream.config.name, {
...stream.config,
Expand Down

0 comments on commit ab73147

Please sign in to comment.