IBM / nodejs-idb-connector

A JavaScript (Node.js) library for communicating with Db2 for IBM i, with support for queries, procedures, and much more. Uses traditional callback-style syntax
MIT License
38 stars 23 forks source link

Running drop schema statement hangs #128

Closed abmusse closed 3 years ago

abmusse commented 3 years ago

Describe the bug When trying to drop a schema the program hangs. Looks like the schema get held by a lock.

To Reproduce Steps to reproduce the behavior:

I first created a schema via Run Sql Scripts:

image

Then using idb-connector attempted attempted to drop the schema

const { dbconn, dbstmt, SQL_TXN_NO_COMMIT, SQL_TXN_ISOLATION,
 } = require('idb-connector');

  const schema = 'IDBTEST';
  const dropSchema = `DROP SCHEMA ${schema}`;
  const findSchema = `SELECT SCHEMA_NAME FROM QSYS2.sysschemas WHERE SCHEMA_NAME = '${schema}'`

  const connection = new dbconn();
  connection.debug(true);
  let isolationLevel = connection.getConnAttr(SQL_TXN_ISOLATION);
  console.log('BEFORE: Isolation level is: ', isolationLevel);
  connection.setConnAttr(SQL_TXN_ISOLATION, SQL_TXN_NO_COMMIT);
  isolationLevel = connection.getConnAttr(SQL_TXN_ISOLATION);
  console.log('AFTER: Isolation level is: ', isolationLevel);

  connection.conn('*LOCAL');
  const statement = new dbstmt(connection);

  console.log('finding schema...');
  statement.exec(findSchema, (r, e) => {
    if (e) { throw e; }
    console.log('find schema result: ', r);
    statement.closeCursor();
    console.log('dropping schema...');
    statement.exec(dropSchema, (r2, e2) => {
      if (e2) { throw e2; }
      statement.close();
      connection.disconn();
      connection.close();
    });
  });

Output:

image

image

Trying to drop the schema from Run Sql Scripts:

image

FYI I needed to set the isolation level to no commit to avoid this error:

image

@dmabupt Have you run into this before?

Expected behavior Should be able to drop the schema successfully without hanging

kadler commented 3 years ago

When dropping a schema, if there are unsaved journal receivers the job will go in to message wait indefinitely. I suspect that's what's going on here.

You can double check in WRKACTJOB if the status says "MSGW". If so, you can use option 7 on the job to answer the messages. You can also work around this with reply list entries, but they are system-wide and require special authority to set.

abmusse commented 3 years ago

Spot on there was a QSQSRVR job in MSGW Status. I Hit option 7 and replied with I to continue operation then my code terminated successfully.

image