Skip to content

Commit

Permalink
server.d: safely remove users
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiascode committed Jan 5, 2025
1 parent a2fec1d commit 4629dbe
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/server/server.d
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ class Server
}
}

User[] users_to_remove;

foreach (user_sock, user ; user_socks) {
const recv_ready = read_socks.isSet(user_sock);
const send_ready = write_socks.isSet(user_sock);
Expand Down Expand Up @@ -163,9 +165,12 @@ class Server
}

if (terminating || !recv_success || !send_success)
del_user(user);
users_to_remove ~= user;
}

foreach (user ; users_to_remove)
del_user(user);

if (terminating)
break;
}
Expand Down Expand Up @@ -613,7 +618,8 @@ class Server

private void kick_all_users()
{
foreach (user ; user_list) del_user(user);
// Deleting users while iterating, create a copy of array with .values
foreach (user ; user_list.values) del_user(user);
}

private void kick_user(string username)
Expand Down

0 comments on commit 4629dbe

Please sign in to comment.