-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Expand file tree
/
Copy pathpostgres@3.4.9.patch
More file actions
81 lines (75 loc) · 2.52 KB
/
Copy pathpostgres@3.4.9.patch
File metadata and controls
81 lines (75 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
diff --git a/src/index.js b/src/index.js
--- a/src/index.js
+++ b/src/index.js
@@ -237,12 +237,13 @@
let savepoints = 0
, connection
, prepare = null
+ , closed = false
try {
await sql.unsafe('begin ' + options.replace(/[^a-z ]/ig, ''), [], { onexecute }).execute()
return await Promise.race([
scope(connection, fn),
- new Promise((_, reject) => connection.onclose = reject)
+ new Promise((_, reject) => connection.onclose = e => (closed = true, reject(e)))
])
} catch (error) {
throw error
@@ -289,6 +290,8 @@
}
function handler(q) {
+ if (closed)
+ return q.reject(Errors.connection('CONNECTION_CLOSED', options))
q.catch(e => uncaughtError || (uncaughtError = e))
c.queue === full
? queries.push(q)
diff --git a/cjs/src/index.js b/cjs/src/index.js
--- a/cjs/src/index.js
+++ b/cjs/src/index.js
@@ -237,12 +237,13 @@
let savepoints = 0
, connection
, prepare = null
+ , closed = false
try {
await sql.unsafe('begin ' + options.replace(/[^a-z ]/ig, ''), [], { onexecute }).execute()
return await Promise.race([
scope(connection, fn),
- new Promise((_, reject) => connection.onclose = reject)
+ new Promise((_, reject) => connection.onclose = e => (closed = true, reject(e)))
])
} catch (error) {
throw error
@@ -289,6 +290,8 @@
}
function handler(q) {
+ if (closed)
+ return q.reject(Errors.connection('CONNECTION_CLOSED', options))
q.catch(e => uncaughtError || (uncaughtError = e))
c.queue === full
? queries.push(q)
diff --git a/cf/src/index.js b/cf/src/index.js
--- a/cf/src/index.js
+++ b/cf/src/index.js
@@ -238,12 +238,13 @@
let savepoints = 0
, connection
, prepare = null
+ , closed = false
try {
await sql.unsafe('begin ' + options.replace(/[^a-z ]/ig, ''), [], { onexecute }).execute()
return await Promise.race([
scope(connection, fn),
- new Promise((_, reject) => connection.onclose = reject)
+ new Promise((_, reject) => connection.onclose = e => (closed = true, reject(e)))
])
} catch (error) {
throw error
@@ -290,6 +291,8 @@
}
function handler(q) {
+ if (closed)
+ return q.reject(Errors.connection('CONNECTION_CLOSED', options))
q.catch(e => uncaughtError || (uncaughtError = e))
c.queue === full
? queries.push(q)