clockworklabs/SpacetimeDB · warning · DBError
Client not found
Error message
Client not found: {client_id:?} What it means
ModuleSubscriptionManager::remove_subscription could not find a live entry for the ClientId in its clients map, or the entry is flagged dropped. The unsubscribe arrived after the client's server-side state was already torn down (disconnect cleanup) or the client was never registered. Its subscriptions are removed along with the client state, so the explicit removal has nothing to act on.
Solutions
- Treat it as best-effort: if the client is already gone, its subscriptions were cleaned up with it - ignore the error
- Send unsubscribe before closing the socket, and do not resend it after reconnect since subscription ids do not survive reconnects
- In client SDK teardown paths, catch and suppress this specific error instead of propagating it
Example fix
// before
let queries = manager.remove_subscription(client_id, query_id)?; // may error during disconnect races
// after
match manager.remove_subscription(client_id, query_id) {
Ok(queries) => { /* release query resources */ }
Err(e) if e.to_string().contains("Client not found") => { /* already disconnected; nothing to do */ }
Err(e) => return Err(e),
} Defensive patterns
Strategy: try-catch
Validate before calling
// Ensure the connection is still open before sending Unsubscribe
if connection.is_closed() {
// skip unsubscribe; server cleanup removes subscriptions on disconnect
return Ok(());
} Try / catch
match manager.remove_subscription(client_id, query_id) {
Ok(queries) => { /* release resources */ }
Err(e) if e.to_string().contains("Client not found") => { /* already cleaned up; ignore */ }
Err(e) => return Err(e),
} Prevention
- Send unsubscribe before closing the socket
- Do not resend unsubscribe after reconnect; ids do not survive reconnects
- Treat teardown-path unsubscribe errors as best-effort in client SDKs
When it happens
Trigger: Sending Unsubscribe on a connection that already disconnected (the manager dropped its state), or racing a disconnect: socket close plus cleanup is processed before the explicit unsubscribe message.
Common situations: Client SDKs that both close the socket and send unsubscribe; retrying unsubscribe after a reconnect; disconnect watchdog racing message handling.
Related errors
- `close` was called on this `NoDurability` instance
- failed to look up materialized view args for view
- Got error during read_dir from template directory
- Index ' ' on table ' ' must define a non-empty 'accessor
- unexpected compressed v1 update for v2 subscribe
AI-assisted analysis of clockworklabs/SpacetimeDB@9e0d92412f (2026-08-20).
Data as JSON: /api/errors/b0e3eff117e486b9.
Report an issue: GitHub.
Appendix: source
Thrown at crates/core/src/subscription/module_subscription_manager.rs:847
for id in self.clients.keys().copied().collect::<Vec<_>>() {
if let Some(client) = self.clients.get(&id)
&& client.dropped.load(Ordering::Relaxed)
{
self.remove_all_subscriptions(&id);
}
}
}
/// Remove a single subscription for a client.
/// This will return an error if the client does not have a subscription with the given query id.
pub fn remove_subscription(&mut self, client_id: ClientId, query_id: ClientQueryId) -> Result<Vec<Query>, DBError> {
let subscription_id = (client_id, query_id);
let Some(ci) = self
.clients
.get_mut(&client_id)
.filter(|ci| !ci.dropped.load(Ordering::Acquire))
else {
return Err(anyhow::anyhow!("Client not found: {client_id:?}").into());
};
#[cfg(test)]
ci.assert_ref_count_consistency();
let Some(query_hashes) = ci.v1_subscriptions.remove(&subscription_id) else {
return Err(anyhow::anyhow!("Subscription not found: {subscription_id:?}").into());
};
let mut queries_to_return = Vec::new();
for hash in query_hashes {
let remaining_refs = {
let Some(count) = ci.subscription_ref_count.get_mut(&hash) else {
return Err(anyhow::anyhow!("Query count not found for query hash: {hash:?}").into());
};
*count -= 1;
*count
};
if remaining_refs > 0 {View on GitHub (pinned to 9e0d92412f)