Skip to content

Commit

Permalink
Ensure reserved connections are initialized properly - fixes #718
Browse files Browse the repository at this point in the history
  • Loading branch information
porsager committed Nov 2, 2023
1 parent b25274c commit c084a1c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
queue: queues.closed,
idleTimer,
connect(query) {
initial = query
initial = query || true

This comment has been minimized.

Copy link
@tim-smart

tim-smart Nov 5, 2023

Contributor

@porsager This change seems to prevent onopen(conn) from being called in some cases.

reconnect()
},
terminate,
Expand Down Expand Up @@ -533,11 +533,14 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
return terminate()
}

if (needsTypes)
if (needsTypes) {
initial === true && (initial = null)
return fetchArrayTypes()
}

execute(initial)
options.shared.retries = retries = initial = 0
initial !== true && execute(initial)
options.shared.retries = retries = 0
initial = null

This comment has been minimized.

Copy link
@tim-smart

tim-smart Nov 5, 2023

Contributor

Should if (initial === true) onopen(connection) be added here?

return
}

Expand Down
11 changes: 11 additions & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2543,3 +2543,14 @@ t('reserve connection', async() => {
xs.map(x => x.x).join('')
]
})

t('arrays in reserved connection', async() => {
const reserved = await sql.reserve()
const [{ x }] = await reserved`select array[1, 2, 3] as x`
reserved.release()

return [
'123',
x.join('')
]
})

0 comments on commit c084a1c

Please sign in to comment.