问题
I have the following node.js script which was running great a couple of days ago but now I get this error:
syd@HP-Notebook:~/Desktop$ node db.js
connected to database
{ [Error: Network error] code: 16 }
node: ../src/ioplugin.cc:496: virtual int Couchnode::IoOps::updateEvent(lcb_socket_t, void*, short int, void*, void (*)(lcb_socket_t, short int, void*)): Assertion `socket != __null' failed.
Aborted (core dumped)
and here is the code for db.js:
var crypto = require('crypto');
var db = require('couchbase');
var couchBase = null;
var committed = 0;
var intervalID = null;
function strGen(len) {
var text = '';
var charset = "abcdefghijklmnopqrstuvwxyz";
for (var i = 0; i < len; i++) {
text += charset.charAt(Math.floor(Math.random() * charset.length));
}
return text;
}
function numGen(len) {
var text = '';
var charset = "0123456789";
for (var i = 0; i < len; i++) {
text += charset.charAt(Math.floor(Math.random() * charset.length));
}
return text;
}
function newLat() {
var lat = Math.floor((Math.random() * 2)+1);
if (lat == 1) return 37;
return 38;
}
function createDocument() {
var name = 'Test user #' + committed;
var licensePlates = strGen(3).toUpperCase() +'-'+ numGen(4);
var lat = parseFloat(newLat() + '.' + numGen(8));
var lng = parseFloat('23.' + numGen(8))
var timestamp = (new Date()).getTime().toString();
var docKey = crypto.createHash('md5').update(licensePlates + '-' + name).digest('hex');
var docData = {
'_id' : docKey,
'name' : name,
'lp' : licensePlates,
'lat' : lat,
'lng' : lng,
'timestamp': timestamp
}
//console.log(docKey);
//console.log(docData);
couchBase.set(docKey, JSON.stringify(docData), function(err){
if (err) {
console.log(err);
} else if (committed < 1000) {
committed++;
console.log('#'+committed + ' - ' + ' Committed: ' + docKey);
} else {
clearInterval(intervalID);
console.log('I\'m done!');
}
});
}
db.connect({
'user':'taxi',
'password':'taxi',
'hosts':['127.0.0.1:8091'],
'bucket':'taxi'
}, function(err, cb) {
if (err) {
console.log('TEST');
console.log(err);
} else {
couchBase = cb;
console.log('connected to database');
intervalID = setInterval(function(){createDocument(null, null, null)}, 5);
}
});
I didn't have any issues in the past. This occurred after I installed php 5.4 in ubuntu 12.04 and then returned to php 5.3 because I couldnt make couchbase work with that version of php. FYI php & couchbase work just fine at the moment, but not with node. As you can see the connection with the database is established but the set statement fails. Any info would be greatly appreciated.
UPDATE
Here is the same error from another script:
syd@HP-Notebook:~/Desktop$ node test.js
Connection established!
Function: get
Network error
Error: Network error
at makeError (/home/syd/node_modules/couchbase/lib/bucket.js:578:18)
at getParsedHandler (/home/syd/node_modules/couchbase/lib/bucket.js:625:17)
node: ../src/ioplugin.cc:496: virtual int Couchnode::IoOps::updateEvent(lcb_socket_t, void*, short int, void*, void (*)(lcb_socket_t, short int, void*)): Assertion `socket != __null' failed.
Aborted (core dumped)
For further info regarding this script & source please visit: Couchbase network error when using get & set in bucket.js
P.S. memcache is working fine with node.js I can get & set. couchnode/couchbase is failing!
回答1:
Couchbase C library was updated recently to 2.1.1 and node.js lib wasn't. Lastest working version of C library is 2.0.7. To download it - just replace version number in links from off. site to 2.0.7.
Also created issue on couchbase bugtracker. Hope it will be fixed.
UPD: Fixed in new couchbase nodejs library release: 1.0.0-beta.
来源:https://stackoverflow.com/questions/18374104/couchbase-network-error-16-socket-assertion-failed-in-node-js