diff --git a/src/muxer.ts b/src/muxer.ts index 1773eb2..cf0c012 100644 --- a/src/muxer.ts +++ b/src/muxer.ts @@ -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[] { diff --git a/src/stream.ts b/src/stream.ts index 09b9ebf..5e7df08 100644 --- a/src/stream.ts +++ b/src/stream.ts @@ -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) { // we've already validated that maxStreamWindowSize can't be more than MAX_UINT32 this.recvWindow = Math.min(this.recvWindow * 2, this.config.maxStreamWindowSize) } diff --git a/test/stream.spec.ts b/test/stream.spec.ts index 793eb31..8584e18 100644 --- a/test/stream.spec.ts +++ b/test/stream.spec.ts @@ -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) // 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 () => { @@ -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 () => {