[core] Run traps before exiting