public async Task StartExpiredConnectionCleanupAsync()

in DeviceBridge/Services/ConnectionManager.cs [94:120]


        public async Task StartExpiredConnectionCleanupAsync()
        {
            _logger.Info("Started expired connection cleanup task");

            while (true)
            {
                try
                {
                    var currentTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds();

                    foreach (var entry in _hasTemporaryConnectionUntil)
                    {
                        if (currentTime > entry.Value)
                        {
                            var _ = AssertDeviceConnectionClosedAsync(entry.Key, true /* temporary */).ContinueWith(t => _logger.Error(t.Exception, "Failed to close temporary connection for device {deviceId}", entry.Key), TaskContinuationOptions.OnlyOnFaulted);
                        }
                    }
                }
                catch (Exception e)
                {
                    _logger.Error(e, "Failed to cleanup expired connections");
                }

                // Trigger the next execution
                await Task.Delay(ExpiredConnectionCleanupIntervalMs);
            }
        }