-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 Don't throw errors when an *unused/free* socket has an error in `De…
…velry.HttpAgent`
- Loading branch information
Showing
3 changed files
with
185 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -457,7 +457,7 @@ HttpAgent.setMethod(function createSocketId() { | |
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 0.8.2 | ||
* @version 0.8.2 | ||
* @version 0.9.3 | ||
*/ | ||
HttpAgent.setMethod(function initializeSocket(socket, options) { | ||
|
||
|
@@ -544,6 +544,15 @@ HttpAgent.setMethod(function initializeSocket(socket, options) { | |
|
||
const on_error = (err) => { | ||
|
||
const name = this.getName(options); | ||
|
||
// If the socket had an error while it was free, ignore the error | ||
if (this.freeSockets[name] && this.freeSockets[name].indexOf(socket) !== -1) { | ||
socket.destroy(); | ||
this.removeSocket(socket, options); | ||
return; | ||
} | ||
|
||
const listenerCount = socket.listeners('error').length; | ||
|
||
this.errorSocketCount++; | ||
|
@@ -575,7 +584,12 @@ HttpAgent.setMethod(function initializeSocket(socket, options) { | |
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 0.8.2 | ||
* @version 0.8.2 | ||
* @version 0.9.3 | ||
* | ||
* @param {Object} options | ||
* @param {Function} on_create | ||
* | ||
* @return {Socket} | ||
*/ | ||
HttpAgent.setMethod(function createConnection(options, on_create) { | ||
|
||
|
@@ -604,6 +618,8 @@ HttpAgent.setMethod(function createConnection(options, on_create) { | |
if (new_socket) { | ||
on_new_create(null, new_socket); | ||
} | ||
|
||
return new_socket; | ||
}); | ||
|
||
/** | ||
|
@@ -664,11 +680,16 @@ const HttpsAgent = Fn.inherits('Develry.HttpAgent', function HttpsAgent(options) | |
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 0.8.2 | ||
* @version 0.8.2 | ||
* @version 0.9.3 | ||
* | ||
* @param {Object} options | ||
* @param {Function} on_create | ||
* | ||
* @return {Socket} | ||
*/ | ||
HttpsAgent.setMethod(function createConnection(options) { | ||
HttpsAgent.setMethod(function createConnection(options, on_create) { | ||
|
||
const socket = CREATE_HTTPS_CONNECTION.call(this, options); | ||
const socket = CREATE_HTTPS_CONNECTION.call(this, options, on_create); | ||
|
||
this.initializeSocket(socket, options); | ||
return socket; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters