Last active
December 17, 2015 05:18
-
-
Save benjamind/5556627 to your computer and use it in GitHub Desktop.
Test case for Seg Fault in asynchronous calls to endure from couchnode library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var couchbase = require('couchbase'), | |
async = require('async'), | |
couchbaseConfig = { | |
debug: process.env.COUCHBASE_DEBUG || true, | |
user: process.env.COUCHBASE_USER || '', | |
password: process.env.COUCHBASE_PASSWORD || '', | |
bucket: process.env.COUCHBASE_BUCKET || 'default' | |
}, | |
async = require('async'), | |
defaultHost = 'localhost:8091', | |
bucket = null, | |
couchbase = require('couchbase'); | |
if (process.env.COUCHBASE_HOSTS) { | |
couchbaseConfig.hosts = process.env.COUCHBASE_HOSTS.split(','); | |
} else { | |
if (process.env.COUCHBASE_HOST) { | |
couchbaseConfig.hosts = [ process.env.COUCHBASE_HOST ]; | |
} else { | |
console.log('Warning: no COUCHBASE_HOSTS specified - Using ' + defaultHost); | |
couchbaseConfig.hosts = [ defaultHost ]; | |
} | |
} | |
couchbase.connect(couchbaseConfig, function (err, bkt) { | |
// create documents | |
var longString = "", i, tests = []; | |
for (i=0; i < 5000; i++) { | |
longString += 'a'; | |
} | |
for (i=1; i < 10; i++) { | |
tests.push('test::' + i); | |
} | |
// store object | |
async.each(tests, function(item, callback) { | |
console.log('Creating item ' + item); | |
bkt.set(item, { | |
id: item, | |
otherItem: 'test', | |
longString: longString | |
}, function(err, meta) { | |
if (err) { | |
console.log('Error creating test data ' + item + ' : ' + JSON.stringify(err)); | |
return callback(err); | |
} | |
console.log('Item created'); | |
bkt.endure(item, {persisted: 1, replicated: 0}, function(err, meta) { | |
if (err) { | |
return callback(err, null); | |
} | |
console.log('Item persisted'); | |
callback(); | |
}); | |
}); | |
},function(err) { | |
if (err) { | |
console.log('Error creating items : ' + err); | |
setTimeout(function() { | |
process.exit(-1); | |
},500); | |
} else { | |
// delete items | |
async.each(tests, function(item, callback) { | |
if (err) { | |
console.log('Error creating test data ' + item + ' : ' + JSON.stringify(err)); | |
return callback(err); | |
} | |
bkt.remove(item, function(err, meta) { | |
callback(); | |
}); | |
}, function(err) { | |
console.log('Completed deletion of items'); | |
setTimeout(function() { | |
process.exit(1); | |
},50); | |
}); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you switch line 36 to
async.eachSeries(tests, function(item, callback) {
the segfault goes away.