Skip to content

Commit 5e70c81

Browse files
committed
Ensure example connection is closed even on error
1 parent c7f38f2 commit 5e70c81

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

examples/webappawait.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,10 @@ async function handleRequest(request, response) {
110110
return;
111111
}
112112

113+
let connection;
113114
try {
114115
// Checkout a connection from the default pool
115-
let connection = await oracledb.getConnection();
116+
connection = await oracledb.getConnection();
116117

117118
const result = await connection.execute(
118119
`SELECT employee_id, first_name, last_name
@@ -121,14 +122,20 @@ async function handleRequest(request, response) {
121122
[deptid] // bind variable value
122123
);
123124

124-
// Release the connection back to the connection pool
125-
await connection.close();
126-
127125
displayResults(response, result, deptid);
126+
128127
} catch (err) {
129128
handleError(response, "handleRequest() error", err);
129+
} finally {
130+
if (connection) {
131+
try {
132+
// Release the connection back to the connection pool
133+
await connection.close();
134+
} catch (err) {
135+
console.error(err);
136+
}
137+
}
130138
}
131-
132139
htmlFooter(response);
133140
}
134141

0 commit comments

Comments
 (0)