private async Task LoadHibernatedSessionsAsync(OperationContext context)
        {
            try
            {
                if (FileSystem.HibernatedSessionsExists(Config.DataRootPath))
                {
                    try
                    {
                        var stopWatch          = Stopwatch.StartNew();
                        var hibernatedSessions = await FileSystem.ReadHibernatedSessionsAsync(Config.DataRootPath);

                        stopWatch.Stop();
                        Tracer.Debug(
                            context, $"Read hibernated sessions from root=[{Config.DataRootPath}] in {stopWatch.Elapsed.TotalMilliseconds}ms");

                        if (hibernatedSessions.Sessions != null && hibernatedSessions.Sessions.Any())
                        {
                            foreach (HibernatedSessionInfo s in hibernatedSessions.Sessions)
                            {
                                Tracer.Debug(context, $"Restoring hibernated session {DescribeHibernatedSessionInfo(s)}.");

                                // If there was no expiration stored, then default to the longer timeout
                                // Otherwise, default to at least the shorter timeout
                                var newExpirationTicks = s.ExpirationUtcTicks == default(long)
                                    ? (DateTime.UtcNow + Config.UnusedSessionTimeout).Ticks
                                    : Math.Max(s.ExpirationUtcTicks, (DateTime.UtcNow + Config.UnusedSessionHeartbeatTimeout).Ticks);

                                var sessionResult = await CreateTempDirectoryAndSessionAsync(
                                    context,
                                    s.Id,
                                    s.Session,
                                    s.Cache,
                                    s.Pin,
                                    s.Capabilities,
                                    newExpirationTicks);

                                if (sessionResult.Succeeded)
                                {
                                    var session = sessionResult.Value.session;
                                    if (s.Pins != null && s.Pins.Any())
                                    {
                                        // Restore pins
                                        var contentHashes = s.Pins.Select(x => new ContentHash(x)).ToList();
                                        if (session is IHibernateContentSession hibernateSession)
                                        {
                                            await hibernateSession.PinBulkAsync(context, contentHashes);
                                        }
                                        else
                                        {
                                            foreach (var contentHash in contentHashes)
                                            {
                                                // Failure should be logged. We can ignore the error in this case.
                                                await session.PinAsync(context, contentHash, CancellationToken.None).IgnoreFailure();
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    Tracer.Warning(context, $"Failed to restore hibernated session, error=[{sessionResult.ErrorMessage}]");
                                }
                            }
                        }
                    }
                    catch (Exception exception)
                    {
                        Tracer.Warning(context, $"Failed to read hibernated sessions root=[{Config.DataRootPath}]: {exception}");
                        Tracer.Error(context, exception);
                    }
                    finally
                    {
                        // Done reading hibernated sessions. No matter what happened, remove the file so we don't attempt to load later.
                        Tracer.Debug(context, $"Deleting hibernated sessions from root=[{Config.DataRootPath}].");
                        await FileSystem.DeleteHibernatedSessions(Config.DataRootPath);
                    }

                    _lastSessionId = _sessionHandles.Any() ? _sessionHandles.Keys.Max() : 0;
                }
            }
            catch (Exception exception)
            {
                Tracer.Error(context, exception, "Failed to load hibernated sessions");
            }
        }
 /// <nodoc />
 public static bool HibernatedSessionsExist(AbsolutePath rootPath, IAbsFileSystem fileSystem)
 => fileSystem.HibernatedSessionsExists(rootPath, HibernatedSessionsFileName);