{"record":{"id":"d702e8ad114b7ef2","repo":"microsoft/FASTER","slug":"error-binding-log-handle-for-segmentfilename-e","errorCode":null,"errorMessage":"Error binding log handle for {segmentFileName}: {e}","messagePattern":"Error binding log handle for (.+?): (.+?)","errorType":"exception","errorClass":"FasterException","httpStatus":null,"severity":"error","filePath":"cs/src/core/Device/LocalStorageDevice.cs","lineNumber":452,"sourceCode":"            }\n\n            if (preallocateFile && segmentSize != -1)\n                SetFileSize(fileName, logHandle, segmentSize);\n\n            if (ioCompletionPort != IntPtr.Zero)\n            {\n                ThreadPool.GetMaxThreads(out int workerThreads, out _);\n                Native32.CreateIoCompletionPort(logHandle, ioCompletionPort, (UIntPtr)(long)logHandle.DangerousGetHandle(), (uint)(workerThreads + NumCompletionThreads));\n            }\n            else\n            {\n                try\n                {\n                    ThreadPool.BindHandle(logHandle);\n                }\n                catch (Exception e)\n                {\n                    throw new FasterException(\"Error binding log handle for \" + segmentFileName + \": \" + e.ToString());\n                }\n            }\n            return logHandle;\n        }\n\n        /// <summary>\n        ///\n        /// </summary>\n        /// <param name=\"segmentId\"></param>\n        /// <returns></returns>\n        protected string GetSegmentName(int segmentId) => GetSegmentFilename(FileName, segmentId);\n\n        /// <summary>\n        /// \n        /// </summary>\n        /// <param name=\"_segmentId\"></param>\n        /// <returns></returns>\n        // Can be used to pre-load handles, e.g., after a checkpoint","sourceCodeStart":434,"sourceCodeEnd":470,"githubUrl":"https://github.com/microsoft/FASTER/blob/321d872eabda6a0345c8bd76419f89723ed864ae/cs/src/core/Device/LocalStorageDevice.cs#L434-L470","documentation":"After creating a segment file handle, LocalStorageDevice binds it to the thread pool for overlapped-I/O completion callbacks. If ThreadPool.BindHandle throws (e.g., handle already bound, invalid, or disposed), the exception is wrapped in a FasterException with the segment filename for context.","triggerScenarios":"CreateHandle with useIoCompletionPort=true when the newly created SafeFileHandle cannot be bound to the thread pool — typically due to an invalid or already-bound handle or runtime I/O-completion infrastructure failure.","commonSituations":"Running under constrained environments (some containers/hosting sandboxing) where I/O completion ports behave unexpectedly; handle races during rapid segment create/dispose; corrupted runtime state.","solutions":["Construct the device with useIoCompletionPort: false to skip the I/O completion port path.","Re-run the operation to rule out a transient handle race during segment creation.","Check for duplicate construction/disposal races on the same device instance.","Report the inner exception details; verify .NET runtime version health on the host."],"exampleFix":"// before\nvar device = new LocalStorageDevice(path, deleteOnClose: false);\n// after\nvar device = new LocalStorageDevice(path, deleteOnClose: false, useIoCompletionPort: false);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { device = new LocalStorageDevice(path, useIoCompletionPort: true); } catch (FasterException e) when (e.Message.StartsWith(\"Error binding log handle\")) { device = new LocalStorageDevice(path, useIoCompletionPort: false); }","preventionTips":["Avoid rapid create/dispose races on device instances.","If running in sandboxed/container environments, prefer useIoCompletionPort: false.","Include the inner exception text when reporting the failure."],"tags":["windows","io-completion-port","threadpool","storage-device"],"backgroundTag":"internal-invariant-violation","analyzedSha":"321d872eabda6a0345c8bd76419f89723ed864ae","analyzedAt":"2026-09-15T22:18:00.693Z","contentChangedAt":"2026-09-15T22:18:00.693Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}