From 1d03f62444a969b44e566822b1501d34db74d382 Mon Sep 17 00:00:00 2001 From: Brendan Coles Date: Sat, 23 Oct 2021 11:49:27 +0000 Subject: [PATCH] EchoServer: Defer removal of client from clients HashMap This is necessary to avoid trying to destruct the on_ready_to_read function from inside the function. --- Userland/Services/EchoServer/main.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Userland/Services/EchoServer/main.cpp b/Userland/Services/EchoServer/main.cpp index 49b7af3965..b77565cea9 100644 --- a/Userland/Services/EchoServer/main.cpp +++ b/Userland/Services/EchoServer/main.cpp @@ -62,8 +62,10 @@ int main(int argc, char** argv) auto client = Client::create(id, move(client_socket)); client->on_exit = [&clients, id] { - clients.remove(id); - outln("Client {} disconnected", id); + Core::deferred_invoke([&clients, id] { + clients.remove(id); + outln("Client {} disconnected", id); + }); }; clients.set(id, client); };