Skip to content

Commit 5e1e893

Browse files
committed
Fixed bug in expiry time handling
1 parent ddeef04 commit 5e1e893

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/v1/routing-driver.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import Session from './session';
2121
import {Driver, READ, WRITE} from './driver';
2222
import {newError, SERVICE_UNAVAILABLE, SESSION_EXPIRED} from "./error";
2323
import RoundRobinArray from './internal/round-robin-array';
24+
import {int} from './integer'
25+
import Integer from './integer'
2426
import "babel-polyfill";
2527

2628
/**
@@ -139,13 +141,13 @@ class ClusterView {
139141
this.routers = routers || new RoundRobinArray();
140142
this.readers = readers || new RoundRobinArray();
141143
this.writers = writers || new RoundRobinArray();
142-
this._expires = expires || -1;
144+
this._expires = expires || int(-1);
143145

144146
}
145147

146148
needsUpdate() {
147-
return this._expires < Date.now() ||
148-
this.routers.empty() ||
149+
return this._expires.lessThan(Date.now()) ||
150+
this.routers.size() <= 1 ||
149151
this.readers.empty() ||
150152
this.writers.empty();
151153
}
@@ -196,10 +198,13 @@ function newClusterView(session) {
196198
return Promise.reject(newError("Invalid routing response from server", SERVICE_UNAVAILABLE));
197199
}
198200
let record = res.records[0];
199-
//Note we are loosing precision here but let's hope that in
200-
//the 140000 years to come before this precision loss
201-
//hits us, that we get native 64 bit integers in javascript
202-
let expires = record.get('ttl').toNumber();
201+
let now = int(Date.now());
202+
let expires = record.get('ttl').multiply(1000).add(now);
203+
//if the server uses a really big expire time like Long.MAX_VALUE
204+
//this may have overflowed
205+
if (expires.lessThan(now)) {
206+
expires = Integer.MAX_VALUE;
207+
}
203208
let servers = record.get('servers');
204209
let routers = new RoundRobinArray();
205210
let readers = new RoundRobinArray();

0 commit comments

Comments
 (0)