Skip to content

Commit e7bcac0

Browse files
authored
Merge pull request #296 from lutovich/1.5-conn-timeout-default-value
Set default connection timeout to 5 seconds
2 parents 56941b8 + 04c86b9 commit e7bcac0

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

src/v1/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ const USER_AGENT = "neo4j-javascript/" + VERSION;
144144
*
145145
* // Specify socket connection timeout in milliseconds. Non-numeric, negative and zero values are treated as an
146146
* // infinite timeout. Connection will be then bound by the timeout configured on the operating system level.
147-
* // Timeout value should be numeric and greater or equal to zero.
147+
* // Timeout value should be numeric and greater or equal to zero. Default value is 5000 which is 5 seconds.
148148
* connectionTimeout: 5000, // 5 seconds
149149
* }
150150
*

src/v1/internal/ch-config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import hasFeature from './features';
2121
import {SERVICE_UNAVAILABLE} from '../error';
2222

23-
const DEFAULT_CONNECTION_TIMEOUT_MILLIS = 0; // turned off by default
23+
const DEFAULT_CONNECTION_TIMEOUT_MILLIS = 5000; // 5 seconds by default
2424

2525
export default class ChannelConfig {
2626

test/internal/ch-config.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,16 @@ describe('ChannelConfig', () => {
110110
expect(config.connectionErrorCode).toEqual(SERVICE_UNAVAILABLE);
111111
});
112112

113+
it('should have connection timeout by default', () => {
114+
const config = new ChannelConfig('', 42, {}, '');
115+
116+
expect(config.connectionTimeout).toEqual(5000);
117+
});
118+
119+
it('should respect configured connection timeout', () => {
120+
const config = new ChannelConfig('', 42, {connectionTimeout: 424242}, '');
121+
122+
expect(config.connectionTimeout).toEqual(424242);
123+
});
124+
113125
});

types/v1/driver.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ declare interface Config {
4848
maxTransactionRetryTime?: number;
4949
loadBalancingStrategy?: LoadBalancingStrategy;
5050
maxConnectionLifetime?: number;
51+
connectionTimeout?: number;
5152
}
5253

5354
declare type SessionMode = "READ" | "WRITE";

0 commit comments

Comments
 (0)