Skip to content

Commit 1525f32

Browse files
dirkdev98porsager
authored andcommitted
Fix writing host and port on connection timeouts
1 parent 7e4f76d commit 1525f32

File tree

6 files changed

+57
-0
lines changed

6 files changed

+57
-0
lines changed

cjs/src/connection.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,9 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
339339
return socket.connect(options.path)
340340

341341
socket.connect(port[hostIndex], host[hostIndex])
342+
socket.host = host[hostIndex]
343+
socket.port = port[hostIndex]
344+
342345
hostIndex = (hostIndex + 1) % port.length
343346
}
344347

cjs/tests/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,6 +1575,22 @@ t('connect_timeout throws proper error', async() => [
15751575
})`select 1`.catch(e => e.code)
15761576
])
15771577

1578+
t('connect_timeout error message includes host:port', { timeout: 20 }, async() => {
1579+
const connect_timeout = 0.2
1580+
const server = net.createServer()
1581+
server.listen()
1582+
const sql = postgres({ port: server.address().port, host: '127.0.0.1', connect_timeout })
1583+
const port = server.address().port
1584+
let err
1585+
await sql`select 1`.catch((e) => {
1586+
if (e.code !== 'CONNECT_TIMEOUT')
1587+
throw e
1588+
err = e.message
1589+
})
1590+
server.close()
1591+
return [["write CONNECT_TIMEOUT 127.0.0.1:", port].join(""), err]
1592+
})
1593+
15781594
t('requests works after single connect_timeout', async() => {
15791595
let first = true
15801596

deno/src/connection.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,9 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
343343
return socket.connect(options.path)
344344

345345
socket.connect(port[hostIndex], host[hostIndex])
346+
socket.host = host[hostIndex]
347+
socket.port = port[hostIndex]
348+
346349
hostIndex = (hostIndex + 1) % port.length
347350
}
348351

deno/tests/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,6 +1577,22 @@ t('connect_timeout throws proper error', async() => [
15771577
})`select 1`.catch(e => e.code)
15781578
])
15791579

1580+
t('connect_timeout error message includes host:port', { timeout: 20 }, async() => {
1581+
const connect_timeout = 0.2
1582+
const server = net.createServer()
1583+
server.listen()
1584+
const sql = postgres({ port: server.address().port, host: '127.0.0.1', connect_timeout })
1585+
const port = server.address().port
1586+
let err
1587+
await sql`select 1`.catch((e) => {
1588+
if (e.code !== 'CONNECT_TIMEOUT')
1589+
throw e
1590+
err = e.message
1591+
})
1592+
server.close()
1593+
return [["write CONNECT_TIMEOUT 127.0.0.1:", port].join(""), err]
1594+
})
1595+
15801596
t('requests works after single connect_timeout', async() => {
15811597
let first = true
15821598

src/connection.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,9 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
339339
return socket.connect(options.path)
340340

341341
socket.connect(port[hostIndex], host[hostIndex])
342+
socket.host = host[hostIndex]
343+
socket.port = port[hostIndex]
344+
342345
hostIndex = (hostIndex + 1) % port.length
343346
}
344347

tests/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,6 +1575,22 @@ t('connect_timeout throws proper error', async() => [
15751575
})`select 1`.catch(e => e.code)
15761576
])
15771577

1578+
t('connect_timeout error message includes host:port', { timeout: 20 }, async() => {
1579+
const connect_timeout = 0.2
1580+
const server = net.createServer()
1581+
server.listen()
1582+
const sql = postgres({ port: server.address().port, host: '127.0.0.1', connect_timeout })
1583+
const port = server.address().port
1584+
let err
1585+
await sql`select 1`.catch((e) => {
1586+
if (e.code !== 'CONNECT_TIMEOUT')
1587+
throw e
1588+
err = e.message
1589+
})
1590+
server.close()
1591+
return [["write CONNECT_TIMEOUT 127.0.0.1:", port].join(""), err]
1592+
})
1593+
15781594
t('requests works after single connect_timeout', async() => {
15791595
let first = true
15801596

0 commit comments

Comments
 (0)