Skip to content

Commit

Permalink
Fix stamp file names data race
Browse files Browse the repository at this point in the history
Data race occurs in this.processedCacheFile after timeouts in runBin callbacks
  • Loading branch information
oxidase committed Sep 5, 2016
1 parent e2f01ff commit 1b4f087
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions features/support/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,36 +163,36 @@ module.exports = function () {
});
};

this.extractData = (callback) => {
fs.exists(this.processedCacheFile + '.extract', (exists) => {
this.extractData = (stamp, callback) => {
fs.exists(stamp, (exists) => {
if (exists) return callback();

this.runBin('osrm-extract', util.format('%s --profile %s %s', this.extractArgs, this.profileFile, this.inputCacheFile), this.environment, (err) => {
if (err) {
return callback(new Error(util.format('osrm-extract exited with code %d: %s', err.code, err)));
}
fs.writeFile(this.processedCacheFile + '.extract', 'ok', callback);
fs.writeFile(stamp, 'ok', callback);
});
});
};

this.contractData = (callback) => {
fs.exists(this.processedCacheFile + '.contract', (exists) => {
this.contractData = (stamp, callback) => {
fs.exists(stamp, (exists) => {
if (exists) return callback();

this.runBin('osrm-contract', util.format('%s %s', this.contractArgs, this.processedCacheFile), this.environment, (err) => {
if (err) {
return callback(new Error(util.format('osrm-contract exited with code %d: %s', err.code, err)));
}
fs.writeFile(this.processedCacheFile + '.contract', 'ok', callback);
fs.writeFile(stamp, 'ok', callback);
});
});
};

this.extractAndContract = (callback) => {
let queue = d3.queue(1);
queue.defer(this.extractData.bind(this));
queue.defer(this.contractData.bind(this));
queue.defer(this.extractData.bind(this), this.processedCacheFile + '.extract');
queue.defer(this.contractData.bind(this), this.processedCacheFile + '.contract');
queue.awaitAll(callback);
};

Expand Down

0 comments on commit 1b4f087

Please sign in to comment.