Skip to content

Connection timeout #286

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 15, 2017
Merged

Connection timeout #286

merged 2 commits into from
Sep 15, 2017

Conversation

lutovich
Copy link
Contributor

Added ability to enforce max connection timeout. It is applied to new connections and makes them terminate connection attempt after configured number of milliseconds. Feature is needed because connect part might take minutes in some environments.

NodeJS channel uses net.Socket when non-encrypted and it's subclass tls.TLSSocket when encrypted. Connection timeout is implemented using socket.setTimeout() function which triggers a callback after configured millis of inactivity. We first initiate a connection attempt and them set the timeout. If connection establishes before the timeout then later is canceled. Otherwise timeout event is fired and socket is destroyed.

WebSocket channel used in browser does not have built-in timeout functionality. That is why we simply use setTimeout() that closes WebSocket if it does not connect in time. Successful connection cancels the timeout.

Feature is turned of by default and can be configured using connectionTimeout property in the config. Example:

const driver = neo4j.driver(
                    'bolt://localhost',
                    neo4j.auth.basic('neo4j', 'pwd'),
                    {connectionTimeout: 5000 /* 5 seconds */ });

@lutovich lutovich requested a review from zhenlineo September 14, 2017 18:24
Added ability to enforce max connection timeout. It is applied to new
connections and makes them terminate connection attempt after
configured number of milliseconds. Feature is needed because connect
part might take minutes in some environments.

NodeJS channel uses `net.Socket` when non-encrypted and it's subclass
`tls.TLSSocket` when encrypted. Connection timeout is implemented using
`socket.setTimeout()` function which triggers a callback after
configured millis of inactivity. We first initiate a connection attempt
and them set the timeout. If connection establishes before the timeout
then later is canceled. Otherwise `timeout` event is fired and socket
is destroyed.

WebSocket channel used in browser does not have built-in timeout
functionality. That is why we simply use `setTimeout()` that closes
WebSocket if it does not connect in time. Successful connection
cancels the timeout.

Feature is turned of by default and can be configured using
`connectionTimeout` property in the config. Example:

```
const driver = neo4j.driver(
                    'bolt://localhost',
                    neo4j.auth.basic('neo4j', 'pwd'),
                    {connectionTimeout: 5000 /* 5 seconds */ });
```
@lutovich lutovich force-pushed the 1.4-connection-timeout branch from 223cc72 to c5fd1a9 Compare September 14, 2017 22:06
@zhenlineo zhenlineo merged commit 548cbec into neo4j:1.4 Sep 15, 2017
@lutovich lutovich deleted the 1.4-connection-timeout branch September 15, 2017 22:40
@lutovich lutovich mentioned this pull request Sep 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants