Skip to content

Commit 10c6d5f

Browse files
committed
[misc] Deno compatibility: send COM_QUIT synchronously to prevent socket cleanup race condition
1 parent 0dc25c3 commit 10c6d5f

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

lib/connection.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -708,8 +708,16 @@ class Connection extends EventEmitter {
708708
const quitCmd = new Quit(cmdParam, ended, ended);
709709
this.sendQueue.push(quitCmd);
710710
this.receiveQueue.push(quitCmd);
711+
712+
// Deno compatibility: send QUIT immediately to avoid socket resource cleanup issues
713+
const isDeno = typeof Deno !== 'undefined';
711714
if (this.sendQueue.length === 1) {
712-
process.nextTick(this.nextSendCmd.bind(this));
715+
if (isDeno) {
716+
// Send synchronously in Deno to ensure COM_QUIT is sent before socket cleanup
717+
this.nextSendCmd();
718+
} else {
719+
process.nextTick(this.nextSendCmd.bind(this));
720+
}
713721
}
714722
} else resolve();
715723
}
@@ -774,7 +782,12 @@ class Connection extends EventEmitter {
774782
self.sendQueue.push(quitCmd);
775783
self.receiveQueue.push(quitCmd);
776784
if (self.sendQueue.length === 1) {
777-
process.nextTick(self.nextSendCmd.bind(self));
785+
const isDeno = typeof Deno !== 'undefined';
786+
if (isDeno) {
787+
self.nextSendCmd();
788+
} else {
789+
process.nextTick(self.nextSendCmd.bind(self));
790+
}
778791
}
779792
});
780793
} else {

0 commit comments

Comments
 (0)