runtimes/core: avoid exit-time teardown race on shutdown (#2482)