Skip to content
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

fix: poor outgoing network performance on Mac #20062

Merged
merged 7 commits into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion packages/network/lib/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function byPortAndAddress (port: number, address: net.Address) {
// https://nodejs.org/api/net.html#net_net_connect_port_host_connectlistener
return new Bluebird<net.Address>((resolve, reject) => {
const onConnect = () => {
client.end()
client.destroy()
resolve(address)
}

Expand Down
27 changes: 27 additions & 0 deletions packages/network/test/unit/connect_spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { connect } from '../..'
import { expect } from 'chai'
import sinon from 'sinon'
import net from 'net'

describe('lib/connect', () => {
context('.byPortAndAddress', () => {
it('destroy connection immediately onConnect', () => {
const socket = new net.Socket()
const destroy = sinon.spy(socket, 'destroy')

sinon.stub(net, 'connect').callsFake((port, address, onConnect) => {
process.nextTick(() => {
onConnect()
})

return socket
})

return connect.byPortAndAddress(1234, { address: '127.0.0.1' })
.then((address) => {
expect(address).to.deep.eq({ address: '127.0.0.1' })
expect(destroy).to.be.called
})
})
})
})