Skip to content

Clear connection map on clean up. (dfs 2834) #9111

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

Merged
merged 1 commit into from
Jun 23, 2025
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
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
"morgan": "1.10.0",
"nan": "2.22.2",
"node-addon-api": "8.3.1",
"node-rdkafka": "3.4.0",
"node-rdkafka": "3.4.1",
"performance-now": "2.1.0",
"pg": "8.16.0",
"ping": "0.4.4",
Expand Down
22 changes: 17 additions & 5 deletions src/util/notifications_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,11 @@ class Notificator {
throw err;
} finally {
await log.close();
this.notif_to_connect.clear();
for (const conn of this.connect_str_to_connection.values()) {
conn.destroy();
}
this.connect_str_to_connection.clear();
this.notif_to_connect.clear();
}
}
}
Expand Down Expand Up @@ -272,18 +273,25 @@ class KafkaNotificator {

async connect() {
this.connection = new Kafka.HighLevelProducer(this.connect_obj.kafka_options_object);
dbg.log2("Kafka producer connecting, connect =", this.connect_obj);
await new Promise((res, rej) => {
this.connection.on('ready', () => {
dbg.log2("Kafka producer connected for connection =", this.connect_obj);
res();
});
this.connection.on('connection.failure', err => {
dbg.error("Kafka producer failed to connect. connect = ", this.connect_obj, ", err =", err);
rej(err);
});
this.connection.on('event.log', arg => {
dbg.log1("event log", arg);
dbg.log2("event log", arg);
});
this.connection.on('event.error', arg => {
dbg.error("event error =", arg);
});
this.connection.connect();
});
dbg.log2("Kafka producer's connect done, connect =", this.connect_obj);
this.connection.setPollInterval(100);
}

Expand All @@ -296,10 +304,12 @@ class KafkaNotificator {
Buffer.from(JSON.stringify(notif.notif)),
null,
Date.now(),
(err, offset) => {
err => {
if (err) {
dbg.error("Failed to notify. Connect =", connect_obj, ", notif =", notif);
promise_failure_cb(notif, failure_ctxt, err).then(resolve);
} else {
dbg.log2("Kafka notify successful. Connect =", connect_obj, ", notif =", notif);
resolve();
}
}
Expand All @@ -308,8 +318,10 @@ class KafkaNotificator {
}

destroy() {
this.connection.flush(10000);
this.connection.disconnect();
if (this.connection.isConnected()) {
this.connection.flush(10000);
this.connection.disconnect();
}
}
}

Expand Down