Skip to content

[Bug]:Connection Reuse Issue with use_database() Causing Database Context Contamination #3175

@jac0626

Description

@jac0626

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Description

When multiple MilvusClient instances share the same physical connection (same URI and authentication), calling use_database() on one client modifies the shared GrpcHandler's state, causing other clients to use the wrong database context.

Root Cause

The original design stored db_name as state in GrpcHandler:

  • GrpcHandler maintained _current_db_name or used _db_interceptor to store database information
  • reset_db_name() modified the handler instance's state
  • When clients shared the same physical connection (same alias), modifying one handler's state affected all clients using that handler

Steps to Reproduce

# Client A connects to default database
client_a = MilvusClient(uri="http://localhost:19530", db_name="default")

# Client B connects to the same server, reuses the connection
client_b = MilvusClient(uri="http://localhost:19530", db_name="testdb")

# Client A switches database
client_a.use_database("db1")  # This modifies the shared GrpcHandler state

# Client B's requests incorrectly use "db1" instead of "testdb"
collections = client_b.list_collections()  # ❌ Actually queries db1, not testdb

Expected Behavior

  • Each client should maintain its own independent db_name state
  • Switching database on one client should not affect other clients
  • Physical connections should be safely shareable across different logical databases

Actual Behavior

  • Modifying db_name on one client affects all clients sharing the same physical connection
  • Other clients' requests use the wrong database context
  • This is a shared state contamination issue

Expected Behavior

No response

Steps/Code To Reproduce behavior

Environment details

- Hardware/Softward conditions (OS, CPU, GPU, Memory):
- Method of installation (Docker, or from source):
- Milvus version (v0.3.1, or v0.4.0):
- Milvus configuration (Settings you made in `server_config.yaml`):

Anything else?

No response

Sub-issues

Metadata

Metadata

Assignees

Labels

kind/bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions