Skip to content

Close channels on destroying errors #1215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/bolt-connection/src/channel/node/node-channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ export default class NodeChannel {
'and that you have compatible encryption settings both on Neo4j server and driver. ' +
'Note that the default encryption setting has changed in Neo4j 4.0.'
if (err.message) msg += ' Caused by: ' + err.message
if (this._conn.destroyed) {
this._open = false
}
this._error = newError(msg, this._connectionErrorCode)
if (this.onerror) {
this.onerror(this._error)
Expand Down
26 changes: 26 additions & 0 deletions packages/bolt-connection/test/channel/node/node-channel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,32 @@ describe('NodeChannel', () => {
})
})
})

describe('._HandleConnectionError()', () => {
it('should set open false if connection error on destroyed socket', () => {
const address = ServerAddress.fromUrl('bolt://localhost:9999')
const channelConfig = new ChannelConfig(address, {}, SERVICE_UNAVAILABLE)
const channel = new NodeChannel(channelConfig)

channel._handleConnectionError(newError('mock error',
SERVICE_UNAVAILABLE))

return expect(channel._open).toBe(true)
})

it('should not set open false if connection error on not destroyed socket', () => {
const address = ServerAddress.fromUrl('bolt://localhost:9999')
const channelConfig = new ChannelConfig(address, {}, SERVICE_UNAVAILABLE)
const channel = new NodeChannel(channelConfig)

channel._conn.destroyed = true

channel._handleConnectionError(newError('mock error',
SERVICE_UNAVAILABLE))

return expect(channel._open).toBe(false)
})
})
})

function createMockedChannel (connected, config = { connectionTimeout: 30000 }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ export default class NodeChannel {
'and that you have compatible encryption settings both on Neo4j server and driver. ' +
'Note that the default encryption setting has changed in Neo4j 4.0.'
if (err.message) msg += ' Caused by: ' + err.message
if (this._conn.destroyed) {
this._open = false
}
this._error = newError(msg, this._connectionErrorCode)
if (this.onerror) {
this.onerror(this._error)
Expand Down