Skip to content

Commit

Permalink
fix: res.socket is null in node-v14.x
Browse files Browse the repository at this point in the history
res.socket has been detached from IncomingMessage in node-v14.x

Reference: nodejs/node#32153
  • Loading branch information
hyj1991 committed May 14, 2020
1 parent e4e9137 commit 9552eee
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ node_js:
- '8'
- '10'
- '12'
- '14'
script:
- npm run ci
after_script:
Expand Down
7 changes: 4 additions & 3 deletions lib/urllib.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ exports.requestThunk = function requestThunk(url, args) {
};

function requestWithCallback(url, args, callback) {
var req;
// requestWithCallback(url, callback)
if (!url || (typeof url !== 'string' && typeof url !== 'object')) {
var msg = util.format('expect request url to be a string or a http request options, but got %j', url);
Expand Down Expand Up @@ -592,10 +593,11 @@ function requestWithCallback(url, args, callback) {
if (serverSocketTimeout < freeSocketTimeout) {
// https://github.com/node-modules/agentkeepalive/blob/master/lib/agent.js#L127
// agentkeepalive@4
var socket = res.socket || (req && req.socket);
if (agent.options && agent.options.freeSocketTimeout) {
res.socket.freeSocketTimeout = serverSocketTimeout;
socket.freeSocketTimeout = serverSocketTimeout;
} else {
res.socket.freeSocketKeepAliveTimeout = serverSocketTimeout;
socket.freeSocketKeepAliveTimeout = serverSocketTimeout;
}
}
}
Expand Down Expand Up @@ -966,7 +968,6 @@ function requestWithCallback(url, args, callback) {
}
}

var req;
// request headers checker will throw error
try {
req = httplib.request(options, onResponse);
Expand Down

0 comments on commit 9552eee

Please sign in to comment.