{"record":{"id":"3e90f2d53ec1c0f8","repo":"microsoft/FASTER","slug":"attempt-to-lock-with-unknown-locktype","errorCode":null,"errorMessage":"Attempt to lock with unknown LockType","messagePattern":"Attempt to lock with unknown LockType","errorType":"exception","errorClass":"FasterException","httpStatus":null,"severity":"error","filePath":"cs/src/core/Index/FASTER/Implementation/Locking/OverflowBucketLockTable.cs","lineNumber":69,"sourceCode":"        /// <inheritdoc/>\n        [MethodImpl(MethodImplOptions.AggressiveInlining)]\n        public unsafe bool TryLockManual(ref TKey key, ref HashEntryInfo hei, LockType lockType) \n            => TryLockManual(hei.firstBucket, lockType);\n\n        /// <inheritdoc/>\n        [MethodImpl(MethodImplOptions.AggressiveInlining)]\n        public unsafe bool TryLockManual(long keyCode, LockType lockType) \n            => TryLockManual(GetBucket(keyCode), lockType);\n\n        [MethodImpl(MethodImplOptions.AggressiveInlining)]\n        private unsafe bool TryLockManual(HashBucket* bucket, LockType lockType)\n        {\n            AssertLockAllowed();\n            return lockType switch\n            {\n                LockType.Shared => HashBucket.TryAcquireSharedLatch(bucket),\n                LockType.Exclusive => HashBucket.TryAcquireExclusiveLatch(bucket),\n                _ => throw new FasterException(\"Attempt to lock with unknown LockType\")\n            };\n        }\n\n        /// <inheritdoc/>\n        [MethodImpl(MethodImplOptions.AggressiveInlining)]\n        public unsafe bool TryPromoteLockManual(long keyCode)\n        {\n            AssertLockAllowed();\n            return HashBucket.TryPromoteLatch(GetBucket(keyCode));\n        }\n\n        /// <inheritdoc/>\n        [MethodImpl(MethodImplOptions.AggressiveInlining)]\n        public unsafe bool TryLockTransient(ref TKey key, ref HashEntryInfo hei, LockType lockType) \n            => lockType == LockType.Shared ? TryLockTransientShared(ref key, ref hei) : TryLockTransientExclusive(ref key, ref hei);\n\n        /// <inheritdoc/>\n        [MethodImpl(MethodImplOptions.AggressiveInlining)]","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/microsoft/FASTER/blob/321d872eabda6a0345c8bd76419f89723ed864ae/cs/src/core/Index/FASTER/Implementation/Locking/OverflowBucketLockTable.cs#L51-L87","documentation":"OverflowBucketLockTable.TryLockManual only supports LockType.Shared and LockType.Exclusive; the switch's default arm throws FasterException for any other LockType value. This is an internal argument-validation guard on the lock table API.","triggerScenarios":"Invoking TryLockManual (directly or via lock-orchestrator code) with a LockType other than Shared or Exclusive, e.g. LockType.None or a cast integer producing an undefined value.","commonSituations":"Custom locking/compaction code that passes an uninitialized or default LockType enum value, or enum arithmetic that yields an out-of-range value.","solutions":["Pass exactly LockType.Shared or LockType.Exclusive to TryLockManual.","If the value comes from a variable, assert/validate it before locking: if (lt is not (LockType.Shared or LockType.Exclusive)) throw.","Check for uninitialized (default) enum fields that resolve to an unsupported value."],"exampleFix":"// before\nvar lt = default(LockType);\nlockTable.TryLockManual(keyCode, ref bucket, lt, context);\n// after\nvar lt = LockType.Exclusive;\nif (lt is not (LockType.Shared or LockType.Exclusive))\n    throw new ArgumentOutOfRangeException(nameof(lt));\nlockTable.TryLockManual(keyCode, ref bucket, lt, context);","handlingStrategy":"validation","validationCode":"if (lockType is not (LockType.Shared or LockType.Exclusive))\n    throw new ArgumentOutOfRangeException(nameof(lockType), lockType, \"Only Shared/Exclusive supported\");\nlockTable.TryLockManual(keyCode, ref bucket, lockType, context);","typeGuard":"static bool IsSupportedLockType(LockType lt) => lt is LockType.Shared or LockType.Exclusive;","tryCatchPattern":"catch (FasterException ex) when (ex.Message.Contains(\"unknown LockType\"))\n{ logger.LogError(ex, \"Bad LockType value passed to TryLockManual\"); throw; }","preventionTips":["Never cast integers to LockType; use the named enum members only.","Avoid default(LockType); initialize lock-type fields explicitly.","Add a debug assertion for supported lock types at public lock-helper boundaries."],"tags":["faster","locking","invalid-enum","csharp"],"backgroundTag":"invalid-enum-value","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"}