Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read property 'write' of null at node_modules/nodestalker/lib/beanstalk_client.js:254:15 #23

Open
otobrglez opened this issue Oct 28, 2015 · 5 comments

Comments

@otobrglez
Copy link

Hey guys!

I'm using nodestalker@0.1.18 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
@pascalopitz
Copy link
Owner

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 notifications@github.com wrote:

Hey guys!

I'm using nodestalker@0.1.18 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
#23.

@ericcumbee
Copy link

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)

@pascalopitz
Copy link
Owner

Can you attach a debugger and look at what self is a that stage?
On 13 Nov 2015 12:07, "Eric Cumbee" notifications@github.com 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
#23 (comment)
.

@siddo420
Copy link

siddo420 commented Apr 3, 2016

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
            });

@dimonchoo
Copy link

dimonchoo commented Dec 30, 2018

removing client.disconnect() from my code was help me =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants