|
1 | 1 | use std::collections::HashMap; |
| 2 | +use std::hash::{Hash, Hasher}; |
2 | 3 | use std::sync::Arc; |
3 | 4 |
|
4 | 5 | use crate::auth::{AuthManager, Permission, ResourceType}; |
@@ -66,8 +67,8 @@ impl PgWireServerHandlers for HandlerFactory { |
66 | 67 | } |
67 | 68 |
|
68 | 69 | /// 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; |
71 | 72 |
|
72 | 73 | #[derive(Debug, Clone)] |
73 | 74 | struct ConnectionState { |
@@ -137,8 +138,18 @@ impl DfSessionService { |
137 | 138 | } |
138 | 139 |
|
139 | 140 | 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 |
142 | 153 | } |
143 | 154 |
|
144 | 155 | /// Check if the current user has permission to execute a query |
|
0 commit comments