Node-oracledb: SIGINT not terminating process

Created on 26 Jun 2015  路  24Comments  路  Source: oracle/node-oracledb

when I setup an express app including oracledb and use cntrl + C ( SIGINT ) to terminate the process, the process hangs.
It works fine when I use oracledb with node version v0.10.32 , but I am facing this issue with node versions 0.12.x

bug

All 24 comments

We'll look into this.

I was trying to handle the graceful in Node.js v0.12.x, but found encountered the same situation as sandeshhegde83.

Using following snippets to handle SIGINT signal in Node.js

process.on('SIGINT', function() {
server.close(function(err) {
if (err) winston.error(err);
process.exit(0);
});
});

If I did not init the connection pool object, then it works fine; instead, it looks the server stuck during calling server.close(), and need to wait for timeout (2 minutes) to trigger the callback in server.close().

Even, I try to explicitly perform "connectionPool.terminate()" but still no luck.
It becomes critical as there is not possible way to guarantee the application can handle graceful shutdown now, but choose process.exit(0) right away. :(

I'm having an issue with this too on Mac and Linux.

Two possible workarounds until this is addressed:

  1. From another terminal session: killall node.
  2. Close the terminal window with cmd-w. Then reopen it with cmd-n. If your last command is cd <your pro dir>; node proj.js, you can re-run your app quickly with up-arrow,return.

Hi, I have exactly the same issue, after connection pool is initialised.
Is there any solution or fix to this bug other than workaround proposed by sanfords?

@Nemek not yet. This is high on my list of annoying things but hasn't been investigated yet.

+1 Agreed. Makes development quite annoying!
@Nemek Adding a handler for SIGINT in your node js file may be a good temporary workaround.

process.on('SIGINT',function(){
    process.exit(0);    
});

@pravincar it annoys me too. Luckily often a second ^C seems to work for me.

yes this is quite annoying, +1

I use

// PoolP is promise for a pool, BP is Bluebird
// Doesn't do it itself :(
process.on('SIGINT', () => {
    log.info('releasing Oracle pool')
    poolP
    .then(pool => BP.fromNode(cb => pool.terminate(cb)))
    .then(() => process.exit(0), e => {throw e})
})

This still sticks around if there are unclosed connections so not a panacea.

The same issue occurs on Node v5.x. Having to manually kill the process between between restarts is annoying, the CPU usage of the node process also rises to 100% after a SIGINT is sent (Ctrl+C)

Yep, annoying but always getting pushed down the list by other bugs. It's still very much on my radar.

See #332 for some analysis.

FWIW, i created a sample project that showed this, today. #332 is closed as dup, appropriately, but thought i would share my sample project here just to keep track https://github.com/derickbailey/node-oracledb-cpu-leak

This is still present. Any updates?

@hertzg no updates. Hovering in the queue. What behaviour are you seeing and what behaviour do you want? Are you using process.on('SIGINT'?

@cjbj Exactly the same as the issuer described. With node v5.6.0. I've seen the SIGINT workaround, but not used it as there are other services running in the node process that require graceful exit and calling process.exit() is out of question.

Our platform is heavily using Oracle Database with Java but the current task requires lightweight micro background workers which need to be provisioned and terminated on the fly as separate processes. So this issue is not only an annoyance during development but also makes it very hard to pitch NodeJS with OracleDB.

@hertzg What's the exact behavior you want? You don't want the process to exit - so what do you want to have happen?

From the github account-less developer who looked into this: "Reason for hang and CPU hike: Oracle client registers one signal handler and Node.js also registers one signal handler. When SIGINT received then Oracle client executes these two signal handlers but Node's signal handler re-raises SIGINT again which causes executing these two handlers recursively infinite times." So you will almost certainly need to do your cleanup in the SIGINT handler and then call process.exit(0) to break the recursion.

Closing this. Use the aforementioned solution: a SIGINT handler. I suspect most issues are related to closing the pool with open connections, which is orthogonal to the base question of interrupts.

so the only solution is workaround???

I'm still seeing this issue with node v6.
I've added the SIGINT handler before my connection init, but my --debug=5959 process stays open, so I run into a EADDRINUSE :::5959 when I try to restart.

This works:

process.on("SIGINT", () => {
     closeConnections(),
    .catch((error: any) => {
        console.error(error);
    })
    .then(() => {
        process.kill(process.pid, "SIGTERM");
    });
});

@panuhorsmalahti thanks for sharing that snippet

@panuhorsmalahti do you have a working example of this?

what does closeConnections does?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cristian-programmer picture cristian-programmer  路  4Comments

sibelius picture sibelius  路  4Comments

nicholas-ochoa picture nicholas-ochoa  路  3Comments

rheinripper picture rheinripper  路  4Comments

ChrisHAdams picture ChrisHAdams  路  3Comments