Skip to content

Commit c04eb01

Browse files
authored
fix(db): revert to dedicated sockets db connection establishment (#1581)
1 parent 5d887fd commit c04eb01

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

apps/sim/socket-server/database/operations.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ const connectionString = env.DATABASE_URL
1313
const socketDb = drizzle(
1414
postgres(connectionString, {
1515
prepare: false,
16-
idle_timeout: 20,
17-
connect_timeout: 10,
18-
max: 5,
16+
idle_timeout: 10,
17+
connect_timeout: 20,
18+
max: 15,
1919
onnotice: () => {},
2020
}),
2121
{ schema }
2222
)
2323

24-
// Use dedicated connection for socket operations
24+
// Use dedicated connection for socket operations, fallback to shared db for compatibility
2525
const db = socketDb
2626

2727
// Constants

apps/sim/socket-server/rooms/manager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ const connectionString = env.DATABASE_URL
1111
const db = drizzle(
1212
postgres(connectionString, {
1313
prepare: false,
14-
idle_timeout: 20,
15-
connect_timeout: 10,
14+
idle_timeout: 15,
15+
connect_timeout: 20,
1616
max: 3,
1717
onnotice: () => {},
1818
}),

packages/db/index.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,28 @@ if (!connectionString) {
1010
throw new Error('Missing DATABASE_URL environment variable')
1111
}
1212

13+
console.log(
14+
'[DB Pool Init]',
15+
JSON.stringify({
16+
timestamp: new Date().toISOString(),
17+
nodeEnv: process.env.NODE_ENV,
18+
action: 'CREATING_CONNECTION_POOL',
19+
poolConfig: {
20+
max: 30,
21+
idle_timeout: 20,
22+
connect_timeout: 30,
23+
prepare: false,
24+
},
25+
pid: process.pid,
26+
isProduction: process.env.NODE_ENV === 'production',
27+
})
28+
)
29+
1330
const postgresClient = postgres(connectionString, {
1431
prepare: false,
1532
idle_timeout: 20,
16-
connect_timeout: 10,
17-
max: 20,
33+
connect_timeout: 30,
34+
max: 30,
1835
onnotice: () => {},
1936
})
2037

0 commit comments

Comments
 (0)