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: establish RTT at start of connection #64

Merged
merged 2 commits into from
Nov 14, 2023
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
5 changes: 4 additions & 1 deletion src/muxer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,16 @@ export class YamuxMuxer implements StreamMuxer {
this.nextStreamID = this.client ? 1 : 2

this.nextPingID = 0
this.rtt = 0
this.rtt = -1

this.log?.trace('muxer created')

if (this.config.enableKeepAlive) {
this.keepAliveLoop().catch(e => this.log?.error('keepalive error: %s', e))
}

// send an initial ping to establish RTT
this.ping().catch(e => this.log?.error('ping error: %s', e))
}

get streams (): YamuxStream[] {
Expand Down
2 changes: 1 addition & 1 deletion src/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ export class YamuxStream extends AbstractStream {
// then we (up to) double the recvWindow
const now = Date.now()
const rtt = this.getRTT()
if (flags === 0 && rtt > 0 && now - this.epochStart < rtt * 4) {
if (flags === 0 && rtt > -1 && now - this.epochStart < rtt * 4) {
Copy link
Collaborator Author

@achingbrain achingbrain Nov 13, 2023

Choose a reason for hiding this comment

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

RTT might be less than a ms on a very fast local connection?

🤷

// we've already validated that maxStreamWindowSize can't be more than MAX_UINT32
this.recvWindow = Math.min(this.recvWindow * 2, this.config.maxStreamWindowSize)
}
Expand Down
12 changes: 6 additions & 6 deletions test/stream.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ describe('stream', () => {
// the window capacities should have refilled via window updates as received data was consumed

// eslint-disable-next-line @typescript-eslint/dot-notation
expect(c1['sendWindowCapacity']).to.equal(defaultConfig.initialStreamWindowSize)
expect(c1['sendWindowCapacity']).to.be.gte(defaultConfig.initialStreamWindowSize)
Copy link
Collaborator Author

@achingbrain achingbrain Nov 13, 2023

Choose a reason for hiding this comment

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

These tests have become non-deterministic after this change, sometimes the window is the starting 256KB, sometimes it's been increased to 16MB by the time the test finishes.

// eslint-disable-next-line @typescript-eslint/dot-notation
expect(s1['recvWindowCapacity']).to.equal(defaultConfig.initialStreamWindowSize)
expect(s1['recvWindowCapacity']).to.be.gte(defaultConfig.initialStreamWindowSize)
})

it('test send data - large', async () => {
Expand All @@ -73,9 +73,9 @@ describe('stream', () => {
// the window capacities should have refilled via window updates as received data was consumed

// eslint-disable-next-line @typescript-eslint/dot-notation
expect(c1['sendWindowCapacity']).to.equal(defaultConfig.initialStreamWindowSize)
expect(c1['sendWindowCapacity']).to.be.gte(defaultConfig.initialStreamWindowSize)
// eslint-disable-next-line @typescript-eslint/dot-notation
expect(s1['recvWindowCapacity']).to.equal(defaultConfig.initialStreamWindowSize)
expect(s1['recvWindowCapacity']).to.be.gte(defaultConfig.initialStreamWindowSize)
})

it('test send data - large with increasing recv window size', async () => {
Expand Down Expand Up @@ -105,9 +105,9 @@ describe('stream', () => {
// the window capacities should have refilled via window updates as received data was consumed

// eslint-disable-next-line @typescript-eslint/dot-notation
expect(c1['sendWindowCapacity']).to.be.gt(defaultConfig.initialStreamWindowSize)
expect(c1['sendWindowCapacity']).to.be.gte(defaultConfig.initialStreamWindowSize)
// eslint-disable-next-line @typescript-eslint/dot-notation
expect(s1['recvWindowCapacity']).to.be.gt(defaultConfig.initialStreamWindowSize)
expect(s1['recvWindowCapacity']).to.be.gte(defaultConfig.initialStreamWindowSize)
})

it('test many streams', async () => {
Expand Down