Fix potential race conditions in expiration and background refresh handlers.