Skip to content

restify cannot be imported with latest node v18.0.0 nightly: Request.prototype.closed patch clashes with new Readable.closed getter #1888

Closed
@trentm

Description

@trentm
  • Used appropriate template for the issue type
  • Searched both open and closed issues for duplicates of this issue
  • Title adequately and concisely reflects the feature or the bug

Restify Version: 8.6.0
Node.js Version: v18.0.0-nightly2021111694fa781580 (from https://nodejs.org/download/nightly/v18.0.0-nightly2021111694fa781580/)

Expected behaviour

require('restify') does not throw

Actual behaviour

% node
Welcome to Node.js v18.0.0-nightly2021111694fa781580.
Type ".help" for more information.
> require('restify')
Uncaught TypeError: Cannot set property closed of #<Readable> which has only a getter
    at patch (.../node_modules/restify/lib/request.js:848:30)
    at Object.<anonymous> (.../node_modules/restify/lib/server.js:33:1)
    at Module._compile (node:internal/modules/cjs/loader:1097:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1149:10)
    at Module.load (node:internal/modules/cjs/loader:975:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:999:19)
    at require (node:internal/modules/cjs/helpers:102:18)
>

Repro case

require('restify')

Cause

Node's master branch recently added a closed property to streams.Readable.prototype which only has a getter:
https://github.com/nodejs/node/pull/40696/files#diff-040c1f5a53844e600d40b33c4624f1fe39fcf2f8d62c76ca3fc5ea5442231469

This is incompatible with Restify's patching of http.IncomingMessage (which is a Readable) to add its own closed property:

node-restify/lib/request.js

Lines 839 to 851 in 71c7f49

/**
* Returns true when connection state is "close"
*
* @private
* @memberof Request
* @instance
* @function closed
* @returns {Boolean} is closed
*/
Request.prototype.closed = function closed() {
var self = this;
return self.connectionState() === 'close';
};

Are you willing and able to fix this?

Probably not. I do not use restify currently. I came across this in testing we do on our APM agent's instrumentation of restify. We periodically test against the latest node nightly build.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions