Skip to content

Commit c517fa9

Browse files
authored
Merge pull request #1215 from neo4j/5.x-econnreset-investigation
Close channels on destroying errors
2 parents 6ad3e20 + dd4905e commit c517fa9

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

packages/bolt-connection/src/channel/node/node-channel.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,9 @@ export default class NodeChannel {
290290
'and that you have compatible encryption settings both on Neo4j server and driver. ' +
291291
'Note that the default encryption setting has changed in Neo4j 4.0.'
292292
if (err.message) msg += ' Caused by: ' + err.message
293+
if (this._conn.destroyed) {
294+
this._open = false
295+
}
293296
this._error = newError(msg, this._connectionErrorCode)
294297
if (this.onerror) {
295298
this.onerror(this._error)

packages/bolt-connection/test/channel/node/node-channel.test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,32 @@ describe('NodeChannel', () => {
222222
})
223223
})
224224
})
225+
226+
describe('._HandleConnectionError()', () => {
227+
it('should set open false if connection error on destroyed socket', () => {
228+
const address = ServerAddress.fromUrl('bolt://localhost:9999')
229+
const channelConfig = new ChannelConfig(address, {}, SERVICE_UNAVAILABLE)
230+
const channel = new NodeChannel(channelConfig)
231+
232+
channel._handleConnectionError(newError('mock error',
233+
SERVICE_UNAVAILABLE))
234+
235+
return expect(channel._open).toBe(true)
236+
})
237+
238+
it('should not set open false if connection error on not destroyed socket', () => {
239+
const address = ServerAddress.fromUrl('bolt://localhost:9999')
240+
const channelConfig = new ChannelConfig(address, {}, SERVICE_UNAVAILABLE)
241+
const channel = new NodeChannel(channelConfig)
242+
243+
channel._conn.destroyed = true
244+
245+
channel._handleConnectionError(newError('mock error',
246+
SERVICE_UNAVAILABLE))
247+
248+
return expect(channel._open).toBe(false)
249+
})
250+
})
225251
})
226252

227253
function createMockedChannel (connected, config = { connectionTimeout: 30000 }) {

packages/neo4j-driver-deno/lib/bolt-connection/channel/node/node-channel.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,9 @@ export default class NodeChannel {
290290
'and that you have compatible encryption settings both on Neo4j server and driver. ' +
291291
'Note that the default encryption setting has changed in Neo4j 4.0.'
292292
if (err.message) msg += ' Caused by: ' + err.message
293+
if (this._conn.destroyed) {
294+
this._open = false
295+
}
293296
this._error = newError(msg, this._connectionErrorCode)
294297
if (this.onerror) {
295298
this.onerror(this._error)

0 commit comments

Comments
 (0)