{"record":{"id":"0aaf28f4b6a29be8","repo":"microsoft/FASTER","slug":"lease-acquisition-was-canceled","errorCode":null,"errorMessage":"Lease acquisition was canceled","messagePattern":"Lease acquisition was canceled","errorType":"exception","errorClass":"OperationCanceledException","httpStatus":null,"severity":"warning","filePath":"cs/src/devices/AzureStorageDevice/BlobManager.cs","lineNumber":231,"sourceCode":"                            {\n                                // creation race, try from top\n                                this.TraceHelper.LeaseProgress(\"Creation race observed, retrying\");\n                            }\n\n                            return 1;\n                        });\n\n                    continue;\n                }\n                catch (OperationCanceledException) when (this.StorageErrorHandler.IsTerminated)\n                {\n                    throw; // o.k. during termination or shutdown\n                }\n                catch (Exception e) when (this.StorageErrorHandler.IsTerminated)\n                {\n                    string message = $\"Lease acquisition was canceled\";\n                    this.TraceHelper.LeaseProgress(message);\n                    throw new OperationCanceledException(message, e);\n                }\n                catch (Exception ex) when (numAttempts < BlobManager.MaxRetries\n                    && !this.StorageErrorHandler.IsTerminated && BlobUtils.IsTransientStorageError(ex))\n                {\n                    if (BlobUtils.IsTimeout(ex))\n                    {\n                        this.TraceHelper.FasterPerfWarning($\"Lease acquisition timed out, retrying now\");\n                    }\n                    else\n                    {\n                        TimeSpan nextRetryIn = BlobManager.GetDelayBetweenRetries(numAttempts);\n                        this.TraceHelper.FasterPerfWarning($\"Lease acquisition failed transiently, retrying in {nextRetryIn}\");\n                        await Task.Delay(nextRetryIn);\n                    }\n                    continue;\n                }\n                catch (Exception e) when (!Utils.IsFatal(e))\n                {","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/microsoft/FASTER/blob/321d872eabda6a0345c8bd76419f89723ed864ae/cs/src/devices/AzureStorageDevice/BlobManager.cs#L213-L249","documentation":"BlobManager.AcquireOwnership retries blob lease acquisition while the storage error handler reports the device/service is terminating or shutting down. Instead of continuing to retry, it wraps the triggering exception in an OperationCanceledException with the message 'Lease acquisition was canceled' to signal cooperative cancellation. This is a shutdown-path exception, not a lease contention error.","triggerScenarios":"Calling StartAsync (which acquires the blob lease) while Faster is being terminated: StorageErrorHandler.IsTerminated is true when a storage exception is caught, so acquisition aborts with OperationCanceledException instead of retrying.","commonSituations":"Graceful application shutdown or disposal racing with Faster initialization; host cancellation token fired while StartAsync was still leasing the container; a kubernetes/service shutdown killing the process mid-start.","solutions":["Treat this OperationCanceledException as benign during shutdown; catch it and log instead of failing.","Avoid disposing/stopping the Faster instance while StartAsync is still in flight; await initialization before shutdown.","If it appears outside shutdown, check what set IsTerminated (earlier terminal storage error) and fix that underlying fault."],"exampleFix":"// before\ntask = faster.StartAsync();\n// after: tolerate cancellation during shutdown\ntry { await faster.StartAsync(); }\ncatch (OperationCanceledException) when (shuttingDown) { /* expected during termination */ }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"static bool IsLeaseAcquisitionCanceled(OperationCanceledException ex) =>\n    ex.Message == \"Lease acquisition was canceled\";","tryCatchPattern":"try\n{\n    await device.StartAsync();\n}\ncatch (OperationCanceledException ex) when (ex.Message == \"Lease acquisition was canceled\")\n{\n    logger.LogInformation(\"Lease acquisition canceled due to shutdown; ignoring.\");\n}","preventionTips":["Do not dispose or stop Faster while StartAsync is still running; await initialization first.","Coordinate shutdown with a cancellation token and check it before starting the device.","Log and treat this exception as benign in shutdown paths.","If it occurs during normal operation, investigate the terminal storage error that set IsTerminated."],"tags":["azure-storage","lease","cancellation","shutdown"],"backgroundTag":"operation-canceled","analyzedSha":"321d872eabda6a0345c8bd76419f89723ed864ae","analyzedAt":"2026-09-15T22:18:00.693Z","contentChangedAt":"2026-09-15T22:18:00.693Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}