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

Hubot - robot.http get method returns null body & res. Suspecting hubot timing out #1080

Closed
sggncucumber opened this issue Nov 10, 2015 · 7 comments
Labels

Comments

@sggncucumber
Copy link

Hubo hear is invoking rest api (written node.js) which in turn returns the screenshot url post processing. Since the call would take few mins(3 mins max) hubot is timing out hence I am getting NULL body and res so I could not even check the status code or so.

How to fix the time out issue with hubot. Need your help at the earliest.

sample code,

robot.hear /(.*)command text/i, (res) ->
robot.http("http://localhost:9050/command")
.get() (err, res1, body) ->
res.reply "#{body}"

Here body is displaying as NULL in the rocket chat message. and suspecting the hubot's timeout. Your help is much appreciated...

Regards,
Ganesan S

@sggncucumber
Copy link
Author

Following error is what I am getting as part of get method call...

Error: socket hang up

@sggncucumber
Copy link
Author

Anybody there for the help!!!

@sggncucumber
Copy link
Author

The flow is like this,

  1. user would type the command in ROCKET CHAT
  2. It would be heared by HUBOT which in turn calls another rest api (built on nodejs)
    Since node js would trigger the another script to get the result URL sometimes it would take more time to respond back.
  3. If rest api takes more time then HUBOT simply timedout and return NULL as message body instead of resultant URL. However NodeJS works properly how it suppose to be.

Need your helpt o tweak the HUBOT so that it would wait for longer running scripts. Anything like timeout etc., at HUBOT end???

Your help is much appreciated!!!

@technicalpickles
Copy link
Member

In general, it's important to do error handling when making http calls. body will be undefined if there's an error. See https://github.com/github/hubot/blob/master/docs/scripting.md#error-handling for some examples.

There's not a timeout as far that's hubot specific. robot.http is using https://github.com/technoweenie/node-scoped-http-client which is just a wrapper around the builtin http/https clients. There is a way to configure a timeout, but your code snippet didn't include it (just add .timeout(2000) for example).

It sounds like a problem with the rest API. Are you able to use the /command endpoint from something that isn't hubot?

@bostonaholic
Copy link

bostonaholic commented Apr 30, 2017

@technicalpickles When I add the timeout like you suggested I get the following error:

robot.http(url)
  .timeout(2000)
  .get() (err, res, body) ->
{ Error: socket hang up
  at createHangUpError (_http_client.js:302:15)
  at TLSSocket.socketCloseListener (_http_client.js:334:23)
  at emitOne (events.js:101:20)
  at TLSSocket.emit (events.js:191:7)
  at _handle.close (net.js:510:12)
  at TCP.done [as _onclose] (_tls_wrap.js:332:7)
 code: 'ECONNRESET' }

@technicalpickles
Copy link
Member

@bostonaholic I would make sure you are able to use url from something aside from hubot, ie curl from the command line.

@bostonaholic
Copy link

@technicalpickles I can. And the code works fine without the .timeout. I want to add the timeout because the response can take a few seconds, maybe even up to 10, to respond sometimes.

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

No branches or pull requests

3 participants