1
0
Fork 0

unetmsg: clean up remote data when replacing the incoming connection

Ensure that pub/sub state is in sync

Signed-off-by: Felix Fietkau <nbd@nbd.name>
This commit is contained in:
Felix Fietkau 2025-05-12 11:15:09 +02:00
parent 9bdbe24176
commit 6e60ce007b
1 changed files with 13 additions and 7 deletions

View File

@ -46,6 +46,15 @@ function network_socket_close(data)
data.socket.close();
}
function network_rx_cleanup_state(name)
{
for (let name, sub in core.remote_subscribe)
delete sub[name];
for (let name, sub in core.remote_publish)
delete sub[name];
}
function network_rx_socket_close(data)
{
if (!data)
@ -53,14 +62,10 @@ function network_rx_socket_close(data)
core.dbg(`Incoming connection from ${data.name} closed\n`);
let net = networks[data.network];
if (net && net.rx_channels[data.name] == data)
if (net && net.rx_channels[data.name] != data) {
delete net.rx_channels[data.name];
for (let name, sub in core.remote_subscribe)
delete sub[data.name];
for (let name, sub in core.remote_publish)
delete sub[data.name];
network_rx_cleanup_state(data.name);
}
network_socket_close(data);
}
@ -189,6 +194,7 @@ function network_check_auth(sock_data, info)
if (sock_data.timer)
sock_data.timer.cancel();
sock_data.auth = true;
network_rx_cleanup_state(sock_data.name);
net.rx_channels[sock_data.name] = sock_data;
core.dbg(`Incoming connection from ${sock_data.name} established\n`);