Session timeout: Manually merged in fixes from pull request #2897.