Skip to content

Commit f420322

Browse files
committed
Minor update to the isRecoverable porperty of the Error object
1 parent 373b0f1 commit f420322

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

lib/errors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ function getErr(errorNum) {
741741
args[0] = `${code}: ${baseText}`;
742742
const err = new Error(util.format(...args));
743743
err.code = code;
744-
err.isRecoverable = false;
744+
err.isRecoverable = (errorNum === ERR_CONNECTION_CLOSED);
745745
Error.captureStackTrace(err, getErr);
746746
return err;
747747
}

test/errorTest.js

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,15 @@ describe('240. errorTest.js', function() {
4040

4141
let conn;
4242

43-
before(async () => {
43+
beforeEach(async () => {
4444
conn = await oracledb.getConnection(dbConfig);
4545
});
4646

47-
after(async () => {
48-
if (conn)
47+
afterEach(async () => {
48+
if (conn) {
4949
await conn.close();
50+
conn = null;
51+
}
5052
});
5153

5254
it('240.1 checks the offset value of the error', async () => {
@@ -154,4 +156,43 @@ describe('240. errorTest.js', function() {
154156
conn = undefined;
155157
}); // 240.5
156158

159+
it('240.6 isRecoverable property - kill session immediate', async function() {
160+
// isRecoverable requires Oracle Client 12.1 or later and Oracle Database
161+
// 12.1 or later.
162+
// It also does not work with CMAN-TDM or DRCP.
163+
const isRunnable = await testsUtil.checkPrerequisites(1200000000, 1200000000);
164+
if (!isRunnable || !dbConfig.test.DBA_PRIVILEGE ||
165+
dbConfig.test.drcp || dbConfig.test.isCmanTdm) this.skip();
166+
const dbaConfig = {
167+
user: dbConfig.test.DBA_user,
168+
password: dbConfig.test.DBA_password,
169+
connectionString: dbConfig.connectString,
170+
privilege: oracledb.SYSDBA
171+
};
172+
const sysDBAConn = await oracledb.getConnection(dbaConfig);
173+
174+
const result = await conn.execute(
175+
`select unique
176+
'alter system kill session '''||sid||','||serial#||''' IMMEDIATE;'
177+
from v$session_connect_info
178+
where sid = sys_context('USERENV', 'SID')
179+
`);
180+
// get the SQL to kill the session
181+
const killSql = result.rows[0][0];
182+
// remove the semicolon at the end of the fetched SQL and then execute it
183+
await sysDBAConn.execute(killSql.substring(0, killSql.length - 1));
184+
await sysDBAConn.close();
185+
186+
await assert.rejects(
187+
async () => await conn.commit(),
188+
(err) => {
189+
assert.strictEqual(err.isRecoverable, true);
190+
return true;
191+
}
192+
);
193+
// Using close() on a connection with a killed session throws
194+
// an 'ORA-01012: NOT LOGGED ON' error in Thick mode
195+
if (!oracledb.thin)
196+
conn = undefined;
197+
}); // 240.6
157198
});

test/list.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4971,6 +4971,7 @@ oracledb.OUT_FORMAT_OBJECT and resultSet = true
49714971
240.3 the offset of system error is 0
49724972
240.4 PL/SQL syntax error
49734973
240.5 check isRecoverable property
4974+
240.6 isRecoverable property - kill session immediate
49744975

49754976
241. dbType04.js
49764977
241.1 JSON type check

0 commit comments

Comments
 (0)