Skip to content

Commit

Permalink
when allocating IMAP connection, check if socket is still alive
Browse files Browse the repository at this point in the history
  • Loading branch information
NickOvt committed Jan 6, 2025
1 parent 978ce06 commit 4721069
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions lib/imap-notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,19 +393,29 @@ class ImapNotifier extends EventEmitter {
}

let rlkey = 'lim:' + data.service;
this.counters.limitedcounter(rlkey, data.user, 1, data.limit || 15, (err, res) => {
if (err) {
return callback(err);
}
const { closed: socketClosed, connecting, destroyed } = data.session.socket;

if (!res.success) {
return callback(null, false);
}
if (!socketClosed && !connecting && !destroyed) {
// socket alive, not closed
this.counters.limitedcounter(rlkey, data.user, 1, data.limit || 15, (err, res) => {
if (err) {
return callback(err);
}

this.connectionSessions.set(data.session, { service: data.service, user: data.user });
if (!res.success) {
return callback(null, false);
}

return callback(null, true);
});
this.connectionSessions.set(data.session, { service: data.service, user: data.user });

return callback(null, true);
});
} else {
// socket dead/closed
const err = new Error('[ALERT] Socket closed unexpectedly before authentication completed.');
err.response = 'NO';
return callback(err, false);
}
}

releaseConnection(data, callback) {
Expand Down

0 comments on commit 4721069

Please sign in to comment.