Merge pull request #164 from vibe-d/detect_terminated_drivers

Handle terminated eventcore drivers gracefully when releasing handles.
This commit is contained in:
Leonid Kramer 2019-06-21 21:12:52 +02:00 committed by GitHub
commit 9eeca0ad42
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -8,6 +8,15 @@ void releaseHandle(string subsys, H)(H handle, shared(NativeEventDriver) drv)
if (drv is (() @trusted => cast(shared)eventDriver)()) { if (drv is (() @trusted => cast(shared)eventDriver)()) {
__traits(getMember, eventDriver, subsys).releaseRef(handle); __traits(getMember, eventDriver, subsys).releaseRef(handle);
} else { } else {
// if the owner driver has already been disposed, there is nothing we
// can do anymore
if (!drv.core) {
import vibe.core.log : logWarn;
logWarn("Leaking %s handle %s, because owner thread/driver has already terminated",
H.name, handle.value);
return;
}
// in case the destructor was called from a foreign thread, // in case the destructor was called from a foreign thread,
// perform the release in the owner thread // perform the release in the owner thread
drv.core.runInOwnerThread((h) { drv.core.runInOwnerThread((h) {