我有以下 node.js 脚本,几天前运行良好,但现在出现此错误:
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)
这是 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);
}
});
我过去没有任何问题。这发生在我在 ubuntu 12.04 中安装 php 5.4 然后返回到 php 5.3 之后,因为我无法使 couchbase 与该版本的 php 一起工作。仅供参考 php 和 couchbase 目前工作得很好,但不适用于 node。如您所见,与数据库的连接已建立,但 set 语句失败。任何信息,将不胜感激。
更新
这是另一个脚本的相同错误:
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)
有关此脚本和源的更多信息,请访问:Couchbase network error when using get & set in bucket.js
PS memcache 在 node.js 上运行良好,我可以获取和设置。couchnode/couchbase 失败了!