Skip to content

Commit

Permalink
Merge pull request #373 from vibe-d/graceful_manualevent_gc_leak
Browse files Browse the repository at this point in the history
Handle GC leaks of ManualEvent/ThreadWaiter gracefully
  • Loading branch information
l-kramer authored Dec 17, 2023
2 parents 28410a1 + 942bc41 commit f24acdc
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions source/vibe/core/sync.d
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
module vibe.core.sync;

import vibe.core.log : logDebugV, logTrace, logInfo;
import vibe.core.log;
import vibe.core.task;

import core.atomic;
Expand Down Expand Up @@ -1789,12 +1789,16 @@ private final class ThreadLocalWaiter(bool EVENT_TRIGGERED) {
~this()
{
import vibe.core.internal.release : releaseHandle;
import core.memory : GC;
import core.stdc.stdlib : abort;

if (m_event != EventID.invalid) {
import core.stdc.stdlib : abort;
if (m_driver !is eventDriver) {
abort();
assert(false, "ThreadWaiter destroyed in foreign thread");
logError("ThreadWaiter destroyed in foreign thread");
// handle GC finalization at process exit gracefully, as
// this can happen when tasks/threads have not been properly
// shut down before application exit
if (!GC.inFinalizer()) abort();
}
m_driver.events.releaseRef(m_event);
m_event = EventID.invalid;
Expand Down

0 comments on commit f24acdc

Please sign in to comment.