fix(util/thread_script_state): make sure system does not crash during
finalization
fix(util/thread_script_state): make sure system does not crash during finalization