Session locking and closing