Skip to content

Commit f93d0d4

Browse files
dirkdev98porsager
authored andcommitted
Fix writing host and port on connection timeouts
1 parent 000d058 commit f93d0d4

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
@@ -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

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
@@ -1579,6 +1579,22 @@ t('connect_timeout throws proper error', async() => [
15791579
})`select 1`.catch(e => e.code)
15801580
])
15811581

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

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
@@ -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

0 commit comments

Comments
 (0)