Skip to content

Commit 14d0b93

Browse files
fix: poor outgoing network performance on Mac (#20062)
1 parent 0143e13 commit 14d0b93

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

packages/network/lib/connect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export function byPortAndAddress (port: number, address: net.Address) {
1111
// https://nodejs.org/api/net.html#net_net_connect_port_host_connectlistener
1212
return new Bluebird<net.Address>((resolve, reject) => {
1313
const onConnect = () => {
14-
client.end()
14+
client.destroy()
1515
resolve(address)
1616
}
1717

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { connect } from '../..'
2+
import { expect } from 'chai'
3+
import sinon from 'sinon'
4+
import net from 'net'
5+
6+
describe('lib/connect', () => {
7+
context('.byPortAndAddress', () => {
8+
it('destroy connection immediately onConnect', () => {
9+
const socket = new net.Socket()
10+
const destroy = sinon.spy(socket, 'destroy')
11+
12+
sinon.stub(net, 'connect').callsFake((port, address, onConnect) => {
13+
process.nextTick(() => {
14+
onConnect()
15+
})
16+
17+
return socket
18+
})
19+
20+
return connect.byPortAndAddress(1234, { address: '127.0.0.1' })
21+
.then((address) => {
22+
expect(address).to.deep.eq({ address: '127.0.0.1' })
23+
expect(destroy).to.be.called
24+
})
25+
})
26+
})
27+
})

0 commit comments

Comments
 (0)