Detecting and handling session timeouts