-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
tty: implement ReadStream._final to avoid ENOTCONN on .end() #22900
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,6 +80,7 @@ const { | |
} = errors.codes; | ||
const { validateInt32, validateString } = require('internal/validators'); | ||
const kLastWriteQueueSize = Symbol('lastWriteQueueSize'); | ||
const kShouldShutdown = Symbol('shouldShutdown'); | ||
|
||
// Lazy loaded to improve startup performance. | ||
let cluster; | ||
|
@@ -245,6 +246,10 @@ function Socket(options) { | |
options.writable = options.writable || false; | ||
const { allowHalfOpen } = options; | ||
|
||
// Needed to avoid to call uv_shutdown during _final | ||
// as otherwise it would error with an ENOTCONN. | ||
this[kShouldShutdown] = options.writable; | ||
|
||
// Prevent the "no-half-open enforcer" from being inherited from `Duplex`. | ||
options.allowHalfOpen = true; | ||
// For backwards compat do not emit close on destroy. | ||
|
@@ -359,7 +364,7 @@ Socket.prototype._final = function(cb) { | |
debug('_final: not ended, call shutdown()'); | ||
|
||
// otherwise, just shutdown, or destroy() if not possible | ||
if (!this._handle || !this._handle.shutdown) { | ||
if (!this[kShouldShutdown] || !this._handle || !this._handle.shutdown) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the issue might be that this runs I can try it too (later), but maybe undoing this line change and adding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't because the |
||
cb(); | ||
return this.destroy(); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,7 @@ function ReadStream(fd, options) { | |
} | ||
inherits(ReadStream, net.Socket); | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated change? |
||
ReadStream.prototype.setRawMode = function(flag) { | ||
flag = !!flag; | ||
this._handle.setRawMode(flag); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
|
||
// This tests verifies that process.stdin.end() does not | ||
// crash the process with ENOTCONN | ||
|
||
process.stdin.end(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"to call" -> "calling"