ensure that cleanup runs before the callback is invoked, to prevent for example a thrown exception in the callback preventing the cleanup from happening