node-mongodb-native と EventEmitter の間で奇妙な問題が発生しています。
問題を次のコードに減らしました。
var mongodb = require( 'mongodb' ),
Server = mongodb.Server,
Db = mongodb.Db,
events = require( 'events' ).EventEmitter.prototype;
// Create a mongo client object
var client = new Db( 'tartempion',
new Server(
'127.0.0.1',
27017
)
);
// Open the connection
client.open( function( err, db ) {
if ( err ) throw err;
database = db;
console.log( 'Database driver loaded.' );
events.emit( 'hi' );
});
// If I comment this out, I don't get the error anymore
// and the "Database driver loaded." log is displayed.
events.on( 'hi', function() {
console.log( 'hey man' );
});
そして、私はこのエラーが発生しています:
net.js:140
// Uncomment the following lines after libuv backend is stable and API
^
RangeError: Maximum call stack size exceeded
これはコールバックのイベントに関連している可能性があると思いましたが、このコードは機能します:
events.on( 'hi', function() {
console.log( 'hey man' );
});
f( function() {
events.emit( 'hi' );
});
function f( callback ) {
callback();
}
だから...問題がどこにあるのかわかりません。
参考までに、これを node-mongodb-native issue queueに相互投稿しました。