Skip to content

Commit d24a060

Browse files
committed
make the client_id include socket address so its more unique and can allow connection state isolation
1 parent 79f9e63 commit d24a060

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

datafusion-postgres/src/handlers.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::collections::HashMap;
2+
use std::hash::{Hash, Hasher};
23
use std::sync::Arc;
34

45
use crate::auth::{AuthManager, Permission, ResourceType};
@@ -66,8 +67,8 @@ impl PgWireServerHandlers for HandlerFactory {
6667
}
6768

6869
/// Per-connection transaction state storage
69-
/// We use the process ID as the connection identifier since it's unique per connection
70-
pub type ConnectionId = i32;
70+
/// We use a hash of both PID and secret key as the connection identifier for better uniqueness
71+
pub type ConnectionId = u64;
7172

7273
#[derive(Debug, Clone)]
7374
struct ConnectionState {
@@ -137,8 +138,18 @@ impl DfSessionService {
137138
}
138139

139140
fn get_client_id<C: ClientInfo>(client: &C) -> ConnectionId {
140-
// Use the process ID which is unique per connection
141-
client.pid_and_secret_key().0
141+
// Use a hash of PID, secret key, and socket address for better uniqueness
142+
let (pid, secret) = client.pid_and_secret_key();
143+
let socket_addr = client.socket_addr();
144+
145+
// Create a hash of all identifying values
146+
let mut hasher = std::collections::hash_map::DefaultHasher::new();
147+
pid.hash(&mut hasher);
148+
secret.hash(&mut hasher);
149+
socket_addr.hash(&mut hasher);
150+
151+
let conn_id = hasher.finish();
152+
conn_id
142153
}
143154

144155
/// Check if the current user has permission to execute a query

0 commit comments

Comments
 (0)