SI-6961

Move the thread local `set` call into the `try`-`finally` block.