Skip to content

Commit a77fafc

Browse files
authored
Merge pull request #16 from fasblom/Session-close
Session close
2 parents 9c4b745 + 35b52bf commit a77fafc

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

neo4j.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module.exports = function (RED) {
66

77
var sessions = []
88
var readySessionList = []
9+
const SESSION_TIMEOUT_MS = 4000; // 4 seconds of inactivity
910

1011
node.server = RED.nodes.getNode(config.server)
1112

@@ -38,6 +39,10 @@ module.exports = function (RED) {
3839
database: msg.database || config.database || 'neo4j'
3940
});
4041

42+
if (boltSession.inactivityTimeout) {
43+
clearTimeout(boltSession.inactivityTimeout);
44+
}
45+
4146
let params = null
4247
if (typeof (msg.params) === 'string') {
4348
params = JSON.parse(msg.params)
@@ -119,7 +124,14 @@ module.exports = function (RED) {
119124
.catch(err => {
120125
node.error(err, msg);
121126
}).finally(() => {
127+
// Return the session to the ready pool and set an inactivity timeout
122128
readySessionList.push(readySession)
129+
boltSession.inactivityTimeout = setTimeout(() => {
130+
// Close the session if not used within the timeout period
131+
boltSession.close();
132+
sessions[readySession] = null; // Remove from the session pool
133+
//console.log(`Session ${readySession} closed due to inactivity.`);
134+
}, SESSION_TIMEOUT_MS);
123135
})
124136
} else {
125137
// no sessions available, send the message out on the third port for further processing bty caller

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@
3737
"engines": {
3838
"node": ">=7.4.0"
3939
},
40-
"version": "2.5.2"
40+
"version": "2.5.3"
4141
}

0 commit comments

Comments
 (0)