Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Calling socket.end() is throwing shutdown ENOTCONN #9419

Closed
dougwilson opened this issue Mar 16, 2015 · 5 comments
Closed

Calling socket.end() is throwing shutdown ENOTCONN #9419

dougwilson opened this issue Mar 16, 2015 · 5 comments
Labels

Comments

@dougwilson
Copy link
Member

Hi Node.js, I'm having trouble with something here. In Node.js 0.12, when calling socket.end(), the method call itself is directly throwing the following error:

events.js:85
      throw er; // Unhandled 'error' event
            ^
Error: shutdown ENOTCONN
    at exports._errnoException (util.js:746:11)
    at Socket.onSocketFinish (net.js:232:26)
    at Socket.emit (events.js:104:17)
    at finishMaybe (_stream_writable.js:484:14)
    at endWritable (_stream_writable.js:493:3)
    at Socket.Writable.end (_stream_writable.js:459:5)
    at Socket.end (net.js:407:31)

Well, for one thing, I didn't realize that calling .end() would ever throw an error. Shouldn't the error be emitted as an event on the socket event emitter? I have a user reporting this at mysqljs/mysql#1027 but I don't seem to be able to reproduce on Windows (my only OS) in order to reduce the test case. That user is using OS X, so it's possible it's something OS X-specific.

Any help?

@jasnell
Copy link
Member

jasnell commented Mar 18, 2015

hmm... not certain. can you provide a complete test case that reliably demonstrates the problem.

@dougwilson
Copy link
Member Author

I don't seem to be able to reproduce on Windows and so far only have the stack traces in that link to go off of. That's why I'm asking for help. Can you provide me access to a non-Windows machine, please?

@CamJN
Copy link

CamJN commented Mar 25, 2015

Since this is going no-where fast: I have a minimal and complete test case at: mysqljs/mysql#1027 (comment) and I have to emphasize that using ssl is necessary to see the error. Only node dependency is node-mysql.

Platform is OS X Yosemite (tested on two boxes)
homebrew installed node 0.12 (0.10 does not exhibit this bug)
homebrew installed mysql 5.6.23
You can generate the ssl certs/keys using the commands at mysqljs/mysql#1027 (comment) or your own if you like

@jasnell
Copy link
Member

jasnell commented Mar 25, 2015

@CamJN thank you for the test case. Will do some digging.

@phaux
Copy link

phaux commented May 13, 2015

I have a similar problem when using just the child_process module. I'm trying to stream data directly to/from a ffmpeg process.

When calling .end() on child's pipe I get an error event. The weird thing is that it only happens on pipes with file descriptor above 2, not when it's child's stdin.

When I don't end the stream (using .pipe(…, {end: false})), the ffmpeg process just sits there waiting for more data.

Minimal test case, requires ffmpeg, coffee-script and a test image file picture.jpg.

{createReadStream, createWriteStream} = require 'fs'
{spawn} = require 'child_process'

proc = spawn 'ffmpeg', [
    # input (jpg)
    '-f', 'mjpeg'
    '-i', 'pipe:3'
    # output (png)
    '-f', 'image2'
    '-c:v', 'png'
    'pipe:4'
], stdio: [
    'ignore' # stdin
    'ignore' # stdout
    'ignore' # stderr
    'pipe'
    'pipe'
]

proc.on 'error', (err) -> console.error "Ffmpeg error: #{err}"
proc.on 'exit', (code) -> console.log "Ffmpeg exited with code #{code}"
proc.stdio[3].on 'error', (err) -> console.error "Input error: #{err}"
proc.stdio[4].on 'error', (err) -> console.error "Output error: #{err}"

createReadStream("#{__dirname}/picture.jpg").pipe proc.stdio[3]
proc.stdio[4].pipe createWriteStream "#{__dirname}/output.png"

setTimeout ->
    console.log "Node process didn't crash yet"
, 1000

Output:

Input error: Error: shutdown ENOTCONN
Ffmpeg exited with code 0
Node process didn't crash yet

Everything else works. The output.png file is generated. I'm ignoring the stream errors as a workaround in my script currently.

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

No branches or pull requests

5 participants