From a462db4e04ea4c2f4f227dbf5fc74c605e469340 Mon Sep 17 00:00:00 2001 From: Daniel Graczer Date: Wed, 26 Aug 2020 12:13:21 +0700 Subject: [PATCH] suppressing socketStream warnings during shutdown initiated by SIGINT --- source/eventcore/drivers/posix/driver.d | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/source/eventcore/drivers/posix/driver.d b/source/eventcore/drivers/posix/driver.d index 2ac4e62f..c8f11ecd 100644 --- a/source/eventcore/drivers/posix/driver.d +++ b/source/eventcore/drivers/posix/driver.d @@ -21,6 +21,7 @@ import eventcore.internal.utils; import core.time : MonoTime; import std.algorithm.comparison : among, min, max; +import std.format : format; version (Posix) { package alias sock_t = int; @@ -116,14 +117,23 @@ final class PosixEventDriver(Loop : PosixEventLoop) : EventDriver { return thname.length ? thname : "unknown"; } - if (m_loop.m_handleCount > 0) { + string leaking_handle_desc; + foreach (id, ref s; m_loop.m_fds) { + if (!s.specific.hasType!(typeof(null)) && !(s.common.flags & FDFlags.internal) && + (!s.specific.hasType!(StreamSocketSlot) || s.streamSocket.state == ConnectionState.connected)) + try { + leaking_handle_desc ~= format!" FD %s (%s)\n"(id, s.specific.kind); + } catch (Exception ex) { print("exception happened in Driver.dispose() during formatting"); } + } + + if(leaking_handle_desc.length) { print("Warning (thread: %s): leaking eventcore driver because there are still active handles", getThreadName()); - foreach (id, ref s; m_loop.m_fds) - if (!s.specific.hasType!(typeof(null)) && !(s.common.flags & FDFlags.internal)) - print(" FD %s (%s)", id, s.specific.kind); - return false; + print(leaking_handle_desc); } + if (m_loop.m_handleCount > 0) + return false; + m_processes.dispose(); m_files.dispose(); m_dns.dispose();