node-horseman icon indicating copy to clipboard operation
node-horseman copied to clipboard

Getting "socket hang up" when calling "crop"

Open emarthinsen opened this issue 9 years ago • 7 comments

I have the following code (snippet):

        var timestamp = (new Date()).valueOf();
        var screenshotPath = '/tmp/' + timestamp + '.png';

        return horseman
          .crop('#captcha-container', screenshotPath)

When it runs, the following error is thrown.

Request() error evaluating render() call: Error: socket hang up
HeadlessError: Request() error evaluating render() call: Error: socket hang up
    at ClientRequest.<anonymous> (/var/task/node_modules/node-phantom-simple/node-phantom-simple.js:506:18)
    at emitOne (events.js:77:13)
    at ClientRequest.emit (events.js:169:7)
    at Socket.socketOnEnd (_http_client.js:285:9)
    at emitNone (events.js:72:20)
    at Socket.emit (events.js:166:7)
    at endReadableNT (_stream_readable.js:905:12)
    at nextTickCallbackWith2Args (node.js:437:9)
    at process._tickDomainCallback (node.js:392:17)

What's a little strange about it is that the error appears to be environmental. It is not expressed on my local machine, but is generated when the same code runs on the server.

Does anyone have any idea of how to track down the root cause of this issue? It looks like "socket hang up" covers a wide array of errors.

emarthinsen avatar Jun 01 '16 02:06 emarthinsen

Does it always happen while evaluating render?

awlayton avatar Jun 01 '16 04:06 awlayton

Yes. It's very consistent.

emarthinsen avatar Jun 01 '16 04:06 emarthinsen

It seems like this would be a node-phantom-simple problem, but I am not certain.

awlayton avatar Jun 01 '16 04:06 awlayton

Could you try running it with BLUEBIRD_DEBUG=1 set @emarthinsen? It should make the stack trace more helpful.

awlayton avatar Jun 01 '16 16:06 awlayton

Sorry about the delay. I set the env variable and re-ran. Here's what I'm getting now:

HeadlessError: Request() error evaluating render() call: Error: socket hang up
at ClientRequest.<anonymous> (/var/task/node_modules/node-phantom-simple/node-phantom-simple.js:506:18)
at emitOne (events.js:77:13)
at ClientRequest.emit (events.js:169:7)
at Socket.socketOnEnd (_http_client.js:285:9)
at emitNone (events.js:72:20)
at Socket.emit (events.js:166:7)
at endReadableNT (_stream_readable.js:905:12)
at nextTickCallbackWith2Args (node.js:437:9)
at process._tickDomainCallback (node.js:392:17)
From previous event:
at Horseman.<anonymous> (/var/task/node_modules/node-horseman/lib/actions.js:328:26)
at processImmediate [as _immediateCallback] (timers.js:383:17)
From previous event:
at Horseman.exports.screenshot (/var/task/node_modules/node-horseman/lib/actions.js:327:20)
at Horseman.(anonymous function) [as screenshot] (/var/task/node_modules/node-horseman/lib/index.js:398:17)
at Horseman.screenShot (/var/task/node_modules/node-horseman/lib/actions.js:410:19)
From previous event:
at Horseman.<anonymous> (/var/task/node_modules/node-horseman/lib/actions.js:409:7)
at /var/task/node_modules/node-phantom-simple/node-phantom-simple.js:60:18
at IncomingMessage.<anonymous> (/var/task/node_modules/node-phantom-simple/node-phantom-simple.js:645:9)
at emitNone (events.js:72:20)
at IncomingMessage.emit (events.js:166:7)
at endReadableNT (_stream_readable.js:905:12)
at nextTickCallbackWith2Args (node.js:437:9)
at process._tickDomainCallback (node.js:392:17)
From previous event:
at Horseman.doCrop (/var/task/node_modules/node-horseman/lib/actions.js:391:7)
From previous event:
at Horseman.exports.crop (/var/task/node_modules/node-horseman/lib/actions.js:422:5)
at Horseman.(anonymous function) [as crop] (/var/task/node_modules/node-horseman/lib/index.js:398:17)
at Horseman.<anonymous> (/var/task/merchants/first/solve.js:22:12)
From previous event:
at Horseman.solve (/var/task/merchants/first/solve.js:14:6)
at processImmediate [as _immediateCallback] (timers.js:383:17)
From previous event:
at /var/task/merchants/first/index.js:61:10
at Object.module.exports.scrapeOrder (/var/task/merchants/first/index.js:52:12)
at Request._callback (/var/task/index.js:30:16)
at Request.self.callback (/var/task/node_modules/request/request.js:200:22)
at emitTwo (events.js:87:13)
at Request.emit (events.js:172:7)
at Request.<anonymous> (/var/task/node_modules/request/request.js:1067:10)
at emitOne (events.js:82:20)
at Request.emit (events.js:169:7)
at IncomingMessage.<anonymous> (/var/task/node_modules/request/request.js:988:12)
at emitNone (events.js:72:20)
at IncomingMessage.emit (events.js:166:7)
at endReadableNT (_stream_readable.js:905:12)
at nextTickCallbackWith2Args (node.js:437:9)
at process._tickDomainCallback (node.js:392:17)

emarthinsen avatar Jun 03 '16 22:06 emarthinsen

It seems to be dying inside .screenshot() (which is used by .crop()). Do you get the error if you call .screenshot() instead of .crop() @emarthinsen?

Also, you could try setting DEBUG='horseman*,node-phantom-simple*' when you run it. Perhaps some errors are being logged somewhere.

awlayton avatar Jun 07 '16 19:06 awlayton

I haven't tried .screenshot() in this context. I'll modify the code and give it a shot.

emarthinsen avatar Jun 11 '16 23:06 emarthinsen