Skip to content

Commit

Permalink
fix(runtime): stale cachedData sometimes gets accepted due to some …
Browse files Browse the repository at this point in the history
…bugs in V8, so we need to introduce our own check based on timestamps
  • Loading branch information
artch committed Sep 12, 2017
1 parent db4f3ab commit 6b3a5c1
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,14 @@ process.on('message', (message) => {
let runtimeData = data[0];
let scriptCachedData = {};
var activeSegments, publicSegments, defaultPublicSegment, activeForeignSegment;
scriptCachedData.cachedData = _.mapValues(data[1], i => Buffer.from(i, 'base64'));
if(data[1] && data[1]['.timestamp'] == runtimeData.userCodeTimestamp) {
scriptCachedData.cachedData = {};
for(let i in data[1]) {
if(i != '.timestamp') {
scriptCachedData.cachedData[i] = Buffer.from(data[1][i], 'base64');
}
}
}

runtimeData.staticTerrainData = staticTerrainData;

Expand Down Expand Up @@ -364,7 +371,8 @@ process.on('message', (message) => {
if(scriptCachedData.cachedDataProduced) {
env.hmset(
env.keys.SCRIPT_CACHED_DATA + message.userId,
_.mapValues(scriptCachedData.cachedDataProduced, i => i.toString('base64')))
Object.assign({'.timestamp': runtimeData.userCodeTimestamp},
_.mapValues(scriptCachedData.cachedDataProduced, i => i.toString('base64'))))
.then(() => env.expire(env.keys.SCRIPT_CACHED_DATA + message.userId, 3*3600));

}
Expand Down

0 comments on commit 6b3a5c1

Please sign in to comment.