Skip to content

Commit

Permalink
Avoid scope(failure) to silence unexpected exceptions.
Browse files Browse the repository at this point in the history
scope(failure) will also catch Error in addition to Exception, which may still be generated due to logic errors, and effectively hides the underlying issue.
  • Loading branch information
s-ludwig committed Oct 2, 2024
1 parent 482c820 commit 548d76d
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions source/vibe/core/concurrency.d
Original file line number Diff line number Diff line change
Expand Up @@ -1301,23 +1301,23 @@ ReturnType!CALLABLE performInWorker(CALLABLE, ARGS...)
}
}, () @trusted { return cast(shared)&ctx; } ());

scope (failure) assert(false);

{ // wait for result
auto l = scopedMutexLock(ctx.mutex);
while (!ctx.done) ctx.condition.wait();
}
try {
{ // wait for result
auto l = scopedMutexLock(ctx.mutex);
while (!ctx.done) ctx.condition.wait();
}

// clean up resources
() @trusted {
import core.memory : GC;
destroy(ctx.condition);
destroy(ctx.mutex);
// NOTE: the GC will otherwise call the destructor on the destroy()ed
// Mutex, which causes a failure in DeleteCriticalSection on
// Windows
GC.free(cast(void*)ctx.mutex);
} ();
// clean up resources
() @trusted {
import core.memory : GC;
destroy(ctx.condition);
destroy(ctx.mutex);
// NOTE: the GC will otherwise call the destructor on the destroy()ed
// Mutex, which causes a failure in DeleteCriticalSection on
// Windows
GC.free(cast(void*)ctx.mutex);
} ();
} catch (Exception e) assert(false, e.msg);

static if (!is(ReturnType!CALLABLE == void))
return ctx.result;
Expand Down

0 comments on commit 548d76d

Please sign in to comment.