Skip to content

Commit 72fb90c

Browse files
committed
drain coroutine results on exit
1 parent d7e9963 commit 72fb90c

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

server/src/server.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,16 @@ Server::~Server() {
234234
socketFD_ = -1;
235235
}
236236
for (auto &future : workerFutures_) {
237-
future.Get();
237+
try {
238+
if (future.valid()) {
239+
future.Get();
240+
}
241+
} catch (const std::exception &error) {
242+
std::cerr << "[Server] Worker shutdown failed: " << error.what()
243+
<< std::endl;
244+
} catch (...) {
245+
std::cerr << "[Server] Worker shutdown failed" << std::endl;
246+
}
238247
}
239248
}
240249

@@ -265,6 +274,14 @@ void Server::WorkerLoop(IOUring &ring) {
265274
acceptCoro = AcceptAndProcess(ring);
266275
}
267276
}
277+
278+
for (int attempts = 0; !acceptCoro.isReady() && attempts < 1000;
279+
++attempts) {
280+
ring.Poll();
281+
}
282+
if (acceptCoro.isReady()) {
283+
acceptCoro.Get();
284+
}
268285
} catch (const std::exception &e) {
269286
std::cerr << "[WorkerLoop] Exception: " << e.what() << std::endl;
270287
} catch (...) {

0 commit comments

Comments
 (0)