{"record":{"id":"f782c071d383a4ab","repo":"databendlabs/databend","slug":"contextvar-self-name-has-no-value","errorCode":null,"errorMessage":"ContextVar {self.name} has no value","messagePattern":"ContextVar (.+?) has no value","errorType":"exception","errorClass":"LookupError","httpStatus":null,"severity":"error","filePath":"src/query/script_udf_support/src/transform_udf_script.rs","lineNumber":639,"sourceCode":"                self.var = var\n                self.old = old\n\n        class ContextVar:\n            __slots__ = (\"name\", \"default\", \"_local\")\n\n            def __init__(self, name, *, default=_MISSING):\n                self.name = name\n                self.default = default\n                self._local = threading.local()\n                _REGISTERED_VARS.add(self)\n\n            def get(self, default=_MISSING):\n                value = getattr(self._local, \"value\", _MISSING)\n                if value is _MISSING:\n                    if default is not _MISSING:\n                        return default\n                    if self.default is _MISSING:\n                        raise LookupError(f\"ContextVar {self.name} has no value\")\n                    return self.default\n                return value\n\n            def set(self, value):\n                old = getattr(self._local, \"value\", _MISSING)\n                self._local.value = value\n                return Token(self, old)\n\n            def reset(self, token):\n                if token.var is not self:\n                    raise ValueError(\"Token does not belong to this ContextVar\")\n                if token.old is _MISSING:\n                    if hasattr(self._local, \"value\"):\n                        del self._local.value\n                else:\n                    self._local.value = token.old\n\n        class Context:","sourceCodeStart":621,"sourceCodeEnd":657,"githubUrl":"https://github.com/databendlabs/databend/blob/288d84d76e20a2f8f7173bda9691eb6ece301aa9/src/query/script_udf_support/src/transform_udf_script.rs#L621-L657","documentation":"connect_in_process_grpc establishes an in-memory duplex transport for gRPC by sending the server half of the duplex through a channel to the endpoint task. If that channel's receiver has been dropped (endpoint shut down), the send fails and this io::Error (ConnectionRefused) is returned to the caller.","triggerScenarios":"Calling connect() on an in-process gRPC client after the endpoint/server task has been dropped or shut down; a race where the endpoint is torn down while connections are still being established.","commonSituations":"Meta-service node shutting down while queries still hold a client; tests dropping the server handle before issuing RPCs; mis-ordered teardown of a standalone meta node.","solutions":["Ensure the endpoint task owning the receiver outlives all client connections.","Check node shutdown ordering: stop clients before dropping the in-process endpoint.","If this appears during shutdown, treat it as expected and retry against a healthy node.","Investigate the endpoint drop path (e.g. handle closed early on error) if seen during normal operation."],"exampleFix":"// before\ndrop(endpoint_handle);\nlet client = connect_in_process_grpc().await?;\n// after\nlet client = connect_in_process_grpc().await?;\ndrop(endpoint_handle); // shut down after clients are done","handlingStrategy":"retry","validationCode":"if endpoint_handle_is_dropped() { /* skip connecting */ } // no direct public probe; track endpoint liveness yourself","typeGuard":null,"tryCatchPattern":"match connect_in_process_grpc().await { Err(e) if e.to_string().contains(\"in-process gRPC endpoint closed\") && !shutting_down.load(Relaxed) => restart_endpoint_then_retry(), Err(e) => Err(e.into()), Ok(c) => Ok(c) }","preventionTips":["Keep the endpoint task alive as long as any client may connect","Establish clients before shutting down the meta runtime","Only treat this error as fatal when it occurs outside shutdown"],"tags":["rust","grpc","ipc","shutdown"],"backgroundTag":"connection-refused","analyzedSha":"288d84d76e20a2f8f7173bda9691eb6ece301aa9","analyzedAt":"2026-09-11T11:29:36.208Z","contentChangedAt":"2026-09-11T11:29:36.208Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}