{"record":{"id":"aec4795a18ca8aab","repo":"microsoft/FASTER","slug":"lockablecontext-requires-nameof-concurrencycontrolmode","errorCode":null,"errorMessage":"LockableContext requires {nameof(ConcurrencyControlMode.LockTable)}","messagePattern":"LockableContext requires (.+?)","errorType":"exception","errorClass":"FasterException","httpStatus":null,"severity":"error","filePath":"cs/src/core/ClientSession/ClientSession.cs","lineNumber":257,"sourceCode":"        public LockableUnsafeContext<Key, Value, Input, Output, Context, Functions> LockableUnsafeContext\n        {\n            get\n            {\n                if (!this.fht.LockTable.IsEnabled)\n                    throw new FasterException($\"LockableUnsafeContext requires {nameof(ConcurrencyControlMode.LockTable)}\");\n                return luContext;\n            }\n        }\n\n        /// <summary>\n        /// Return a session wrapper that supports manual locking.\n        /// </summary>\n        public LockableContext<Key, Value, Input, Output, Context, Functions> LockableContext\n        {\n            get\n            {\n                if (!this.fht.LockTable.IsEnabled)\n                    throw new FasterException($\"LockableContext requires {nameof(ConcurrencyControlMode.LockTable)}\");\n                return lContext;\n            }\n        }\n\n        /// <summary>\n        /// Return a session wrapper struct that passes through to client session\n        /// </summary>\n        public BasicContext<Key, Value, Input, Output, Context, Functions> BasicContext => bContext;\n\n        #region IFasterContext\n\n        /// <inheritdoc/>\n        public long GetKeyHash(Key key) => fht.GetKeyHash(ref key);\n\n        /// <inheritdoc/>\n        public long GetKeyHash(ref Key key) => fht.GetKeyHash(ref key);\n\n        /// <inheritdoc/>","sourceCodeStart":239,"sourceCodeEnd":275,"githubUrl":"https://github.com/microsoft/FASTER/blob/321d872eabda6a0345c8bd76419f89723ed864ae/cs/src/core/ClientSession/ClientSession.cs#L239-L275","documentation":"ClientSession.LockableContext supports manual record locking, which only works when the store was created with ConcurrencyControlMode.LockTable. If the lock table is disabled the property throws FasterException, since lock acquisition/release on the returned context could not be honored.","triggerScenarios":"Reading LockableContext on a session whose FasterKV was constructed with ConcurrencyControlMode.None, so fht.LockTable.IsEnabled is false.","commonSituations":"Default FasterKVSettings used (ConcurrencyControlMode.None); migrating code that needs manual locking to an existing store instance that was not configured with LockTable.","solutions":["Set ConcurrencyControlMode = ConcurrencyControlMode.LockTable in FasterKVSettings before constructing FasterKV.","If manual locking is not needed, use the normal Context returned from NewSession instead.","Check fht.LockTable.IsEnabled before accessing LockableContext to fail fast with a clearer message."],"exampleFix":"// before\nvar kv = new FasterKV<Key, Value>(new FasterKVSettings<Key, Value>(path));\nvar lctx = session.LockableContext; // throws\n\n// after\nvar kv = new FasterKV<Key, Value>(new FasterKVSettings<Key, Value>(path) { ConcurrencyControlMode = ConcurrencyControlMode.LockTable });\nvar lctx = session.LockableContext; // ok","handlingStrategy":"validation","validationCode":"if (!fht.LockTable.IsEnabled)\n    throw new InvalidOperationException(\"LockableContext requires ConcurrencyControlMode.LockTable\");\nvar lctx = session.LockableContext;","typeGuard":"bool SupportsManualLocking<TKey, TValue>(FasterKV<TKey, TValue> fht) => fht?.LockTable?.IsEnabled == true;","tryCatchPattern":"try\n{\n    var lctx = session.LockableContext;\n}\ncatch (FasterException ex) when (ex.Message.Contains(\"LockTable\"))\n{\n    // fallback: use regular session context without manual locks\n}","preventionTips":["Keep a single store-configuration module so LockTable mode is never forgotten.","Document the LockTable prerequisite next to every LockableContext usage.","Assert LockTable.IsEnabled in application startup checks."],"tags":["csharp","faster","concurrency","misconfiguration"],"backgroundTag":"feature-not-enabled","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"}