Correctly set thread locals when session times out (#11361, #10995)

Change-Id: I5051cef344f03af276be24a28471a6d6c15b0da6