Skip to content

Commit

Permalink
fix: add missing properties to reserve query
Browse files Browse the repository at this point in the history
Fixes porsager#944

The call to connect(c, query) had no query, so for a connection failure,  query.origin.replace would fail, crashing the process.
  • Loading branch information
aantthony committed Feb 3, 2025
1 parent 089214e commit 7d138dc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,9 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
}

function queryError(query, err) {
if (query === true) {
return;
}
'query' in err || 'parameters' in err || Object.defineProperties(err, {
stack: { value: err.stack + query.origin.replace(/.*\n/, '\n'), enumerable: options.debug },
query: { value: query.string, enumerable: options.debug },
Expand Down
7 changes: 4 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,10 @@ function Postgres(a, b) {
const queue = Queue()
const c = open.length
? open.shift()
: await new Promise(r => {
queries.push({ reserve: r })
closed.length && connect(closed.shift())
: await new Promise((resolve, reject) => {
const q = { reserve: resolve, reject, origin: 'reserve() call', statement: {} };
queries.push(q);
closed.length && connect(closed.shift(), q)
})

move(c, reserved)
Expand Down

0 comments on commit 7d138dc

Please sign in to comment.