Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/core/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,12 @@ const setupConnectTimeout = process.platform === 'win32'

let s1 = null
let s2 = null
const socket = socketWeakRef.deref()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will keep a strong reference of the socket around, preventing its collection. Instead, deference it in the timeout.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. This will prevent the error occurring in "onConnectTimeout" due to the missing socket argument.

const fastTimer = timers.setFastTimeout(() => {
// setImmediate is added to make sure that we prioritize socket error events over timeouts
s1 = setImmediate(() => {
// Windows needs an extra setImmediate probably due to implementation differences in the socket logic
s2 = setImmediate(() => onConnectTimeout(socketWeakRef.deref(), opts))
s2 = setImmediate(() => onConnectTimeout(socket, opts))
})
}, opts.timeout)
return () => {
Expand All @@ -200,10 +201,12 @@ const setupConnectTimeout = process.platform === 'win32'
}

let s1 = null

const socket = socketWeakRef.deref()
const fastTimer = timers.setFastTimeout(() => {
// setImmediate is added to make sure that we prioritize socket error events over timeouts
s1 = setImmediate(() => {
onConnectTimeout(socketWeakRef.deref(), opts)
onConnectTimeout(socket, opts)
})
}, opts.timeout)
return () => {
Expand Down