TypeError: Cannot read property 'write' of null at node_modules/nodestalker/lib/beanstalk_client.js:254:15
Hey guys!
I'm using [email protected] and from time to time I get this error. Error that crashes my Node.js process,...
TypeError: Cannot read property 'write' of null
at <dir>/node_modules/nodestalker/lib/beanstalk_client.js:254:15
at process._tickDomainCallback (node.js:381:11)
Any idea what is going on or how can I fix this?
This is how I'm using nodestalker:
bsClient = bs.Client(config.get('beanstalkd:host') + ':' + config.get('beanstalkd:port'))
.on 'error', (err)->
log.error err
process.exit(1)
putOnTube = (tubeName, payload, priority, delay, ttr, client, callback)->
try
client.use(tubeName).onError (err)->
callback(err, null)
return
.onSuccess (pom)->
pom = null
client
.put(payload, priority, delay, ttr)
.onError (err)->
callback(err, null)
return
.onSuccess (data)->
client.disconnect()
callback(null, data)
return
return
catch error
log.error(error)
pmx.notify(error)
callback(error, null)
return
# Somewhere...
putOnTube 'my_tube', JSON.stringify(is_ok: "ok"), 0, 0, 60, bsClient, callback
Thank you for your comments and effort!
- Oto
https://github.com/pascalopitz/nodestalker/blob/master/lib/beanstalk_client.js#L254
I would say that somehow the connection variable gets lost, as in _self.conn is set to null. Maybe this is because _self is not capturing the right scope anymore?
What version of node are you on, have you got a test case to isolate this, etc etc?
On 28 October 2015 at 19:32, Oto Brglez [email protected] wrote:
Hey guys!
I'm using [email protected] https://github.com/pascalopitz/nodestalker and from time to time I get this error. Error that crashes my Node.js process,...
TypeError: Cannot read property 'write' of null at
/node_modules/nodestalker/lib/beanstalk_client.js:254:15 at process._tickDomainCallback (node.js:381:11) Any idea what is going on or how can I fix this?
This is how I'm using nodestalker:
bsClient = bs.Client(config.get('beanstalkd:host') + ':' + config.get('beanstalkd:port')) .on 'error', (err)-> log.error err process.exit(1) putOnTube = (tubeName, payload, priority, delay, ttr, client, callback)-> try client.use(tubeName).onError (err)-> callback(err, null) return .onSuccess (pom)-> pom = null client .put(payload, priority, delay, ttr) .onError (err)-> callback(err, null) return .onSuccess (data)-> client.disconnect() callback(null, data) return return catch error log.error(error) pmx.notify(error) callback(error, null) return
Somewhere...putOnTube 'my_tube', JSON.stringify(is_ok: "ok"), 0, 0, 60, bsClient, callback
Thank you for your comments and effort!
- Oto
— Reply to this email directly or view it on GitHub https://github.com/pascalopitz/nodestalker/issues/23.
running into a very similar if not identical error. node v0.10.33
/Users/ericcumbee/Desktop/#########/########/node_modules/nodestalker/lib/beanstalk_client.js:292
_self.conn.write(cmd.command());
^
TypeError: Cannot call method 'write' of null
at /Users/ericcumbee/Desktop/######/#####/node_modules/nodestalker/lib/beanstalk_client.js:292:16
at process._tickCallback (node.js:419:13)
Can you attach a debugger and look at what self is a that stage? On 13 Nov 2015 12:07, "Eric Cumbee" [email protected] wrote:
running into a very similar if not identical error. node v0.10.33
/Users/ericcumbee/Desktop/#########/########/node_modules/nodestalker/lib/beanstalk_client.js:292 _self.conn.write(cmd.command()); ^ TypeError: Cannot call method 'write' of null at /Users/ericcumbee/Desktop/######/#####/node_modules/nodestalker/lib/beanstalk_client.js:292:16 at process._tickCallback (node.js:419:13)
— Reply to this email directly or view it on GitHub https://github.com/pascalopitz/nodestalker/issues/23#issuecomment-156290155 .
Similar issue the first time I tried using this module. I am on node 5.10 and whatever the latest is for module (from last night).
Here is my code:
Beanstalkd = require( 'nodestalker' ).Client('127.0.0.1:11300')
....
Beanstalkd.use( 'queue' )
.onSuccess( function( data ){
Beanstalkd.put( job ).onSuccess( function( data ){
Logger.debugc( data ); // prints 1 or sometimes 2
Beanstalkd.disconnect();
}).onError( function( err ){
//never gets called
});
}).onError( function( err ){
//never gets called
});
I dont know how to use the debugger but did object.keys on _self and got the following:
["domain","_events","_eventsCount","_maxListeners","address","port","isRaw","default_priority","reserve_multichunk_timeout","queue","waitingForResponses","conn","waitingForResponse"]
Code that throws error:
process.nextTick(function() {
console.log(JSON.stringify(Object.keys( _self )));
_self.conn.write(cmd.command()); // <--- err is thrown here
});
removing client.disconnect() from my code was help me =)