Skip to content

Set default connection timeout to 5 seconds #296

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
Oct 4, 2017
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
2 changes: 1 addition & 1 deletion src/v1/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ const USER_AGENT = "neo4j-javascript/" + VERSION;
*
* // Specify socket connection timeout in milliseconds. Non-numeric, negative and zero values are treated as an
* // infinite timeout. Connection will be then bound by the timeout configured on the operating system level.
* // Timeout value should be numeric and greater or equal to zero.
* // Timeout value should be numeric and greater or equal to zero. Default value is 5000 which is 5 seconds.
* connectionTimeout: 5000, // 5 seconds
* }
*
Expand Down
2 changes: 1 addition & 1 deletion src/v1/internal/ch-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import hasFeature from './features';
import {SERVICE_UNAVAILABLE} from '../error';

const DEFAULT_CONNECTION_TIMEOUT_MILLIS = 0; // turned off by default
const DEFAULT_CONNECTION_TIMEOUT_MILLIS = 5000; // 5 seconds by default

export default class ChannelConfig {

Expand Down
12 changes: 12 additions & 0 deletions test/internal/ch-config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,16 @@ describe('ChannelConfig', () => {
expect(config.connectionErrorCode).toEqual(SERVICE_UNAVAILABLE);
});

it('should have connection timeout by default', () => {
const config = new ChannelConfig('', 42, {}, '');

expect(config.connectionTimeout).toEqual(5000);
});

it('should respect configured connection timeout', () => {
const config = new ChannelConfig('', 42, {connectionTimeout: 424242}, '');

expect(config.connectionTimeout).toEqual(424242);
});

});
1 change: 1 addition & 0 deletions types/v1/driver.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ declare interface Config {
maxTransactionRetryTime?: number;
loadBalancingStrategy?: LoadBalancingStrategy;
maxConnectionLifetime?: number;
connectionTimeout?: number;
}

declare type SessionMode = "READ" | "WRITE";
Expand Down