Merge pull request #1039 from strongloop/fix/kv-memory-reference-error
kv-memory: fix crash in regular cleanup
This commit is contained in:
commit
b01df10eae
|
@ -31,8 +31,15 @@ KeyValueMemoryConnector.prototype._setupRegularCleanup = function() {
|
||||||
// key expiration too, the scheduled cleanup is merely a performance
|
// key expiration too, the scheduled cleanup is merely a performance
|
||||||
// optimization.
|
// optimization.
|
||||||
var self = this;
|
var self = this;
|
||||||
this._cleanupTimer = setInterval(
|
var timer = this._cleanupTimer = setInterval(
|
||||||
function() { self._removeExpiredItems(); },
|
function() {
|
||||||
|
if (self && self._removeExpiredItems) {
|
||||||
|
self._removeExpiredItems();
|
||||||
|
} else {
|
||||||
|
// The datasource/connector was destroyed - cancel the timer
|
||||||
|
clearInterval(timer);
|
||||||
|
}
|
||||||
|
},
|
||||||
1000);
|
1000);
|
||||||
this._cleanupTimer.unref();
|
this._cleanupTimer.unref();
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,15 +2,9 @@ var kvMemory = require('../lib/connectors/kv-memory');
|
||||||
var DataSource = require('..').DataSource;
|
var DataSource = require('..').DataSource;
|
||||||
|
|
||||||
describe('KeyValue-Memory connector', function() {
|
describe('KeyValue-Memory connector', function() {
|
||||||
var lastDataSource;
|
|
||||||
var dataSourceFactory = function() {
|
var dataSourceFactory = function() {
|
||||||
lastDataSource = new DataSource({ connector: kvMemory });
|
return new DataSource({ connector: kvMemory });
|
||||||
return lastDataSource;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
afterEach(function disconnectKVMemoryConnector() {
|
|
||||||
if (lastDataSource) return lastDataSource.disconnect();
|
|
||||||
});
|
|
||||||
|
|
||||||
require('./kvao.suite')(dataSourceFactory);
|
require('./kvao.suite')(dataSourceFactory);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue