Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 2 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 61 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 41 additions & 24 deletions src/QUICConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1029,30 +1029,47 @@ class QUICConnection {
);
continue;
}

quicStream = QUICStream.createQUICStream({
initiated: 'peer',
streamId,
config: this.config,
connection: this,
codeToReason: this.codeToReason,
reasonToCode: this.reasonToCode,
logger: this.logger.getChild(`${QUICStream.name} ${streamId}`),
});
this.streamMap.set(quicStream.streamId, quicStream);
quicStream.addEventListener(
events.EventQUICStreamSend.name,
this.handleEventQUICStreamSend,
);
quicStream.addEventListener(
events.EventQUICStreamDestroyed.name,
this.handleEventQUICStreamDestroyed,
{ once: true },
);
quicStream.addEventListener(EventAll.name, this.handleEventQUICStream);
this.dispatchEvent(
new events.EventQUICConnectionStream({ detail: quicStream }),
);
try {
this.conn.streamSend(streamId, Buffer.alloc(0), false);
utils.never(
'We never expect the stream to be writable if it was created during the writable iterator',
);
} catch (e) {
// If we got `FinalSize` during the writable iterator then we cleaned up an errant stream
if (e.message === 'FinalSize') continue;
if (utils.isStreamStopped(e) !== false) {
// In this case it was a stream that was created but errored out. We want to create a new stream for this one case.
quicStream = QUICStream.createQUICStream({
initiated: 'peer',
streamId,
config: this.config,
connection: this,
codeToReason: this.codeToReason,
reasonToCode: this.reasonToCode,
logger: this.logger.getChild(`${QUICStream.name} ${streamId}`),
});
this.streamMap.set(quicStream.streamId, quicStream);
quicStream.addEventListener(
events.EventQUICStreamSend.name,
this.handleEventQUICStreamSend,
);
quicStream.addEventListener(
events.EventQUICStreamDestroyed.name,
this.handleEventQUICStreamDestroyed,
{ once: true },
);
quicStream.addEventListener(
EventAll.name,
this.handleEventQUICStream,
);
this.dispatchEvent(
new events.EventQUICConnectionStream({ detail: quicStream }),
);
quicStream.write();
continue;
}
utils.never(`Expected to throw "FinalSize", got ${e.message}`);
}
}
quicStream.write();
}
Expand Down
5 changes: 5 additions & 0 deletions src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ class ErrorQUIC<T> extends AbstractError<T> {
static description = 'QUIC error';
}

class ErrorQUICUndefinedBehaviour<T> extends AbstractError<T> {
static description = 'You should never see this error';
}

class ErrorQUICHostInvalid<T> extends AbstractError<T> {
static description = 'Host provided was not valid';
}
Expand Down Expand Up @@ -293,6 +297,7 @@ class ErrorQUICStreamLimit<T> extends ErrorQUICStream<T> {

export {
ErrorQUIC,
ErrorQUICUndefinedBehaviour,
ErrorQUICHostInvalid,
ErrorQUICPortInvalid,
ErrorQUICConfig,
Expand Down
5 changes: 5 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import * as errors from './errors';
const textEncoder = new TextEncoder();
const textDecoder = new TextDecoder('utf-8');

function never(message: string): never {
throw new errors.ErrorQUICUndefinedBehaviour(message);
}

/**
* Used to yield to the event loop to allow other micro tasks to process
*/
Expand Down Expand Up @@ -572,6 +576,7 @@ function setMaxListeners(
export {
textEncoder,
textDecoder,
never,
yieldMicro,
promisify,
promise,
Expand Down
2 changes: 1 addition & 1 deletion tests/QUICStream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import * as testsUtils from './utils';
import { generateTLSConfig, sleep } from './utils';

describe(QUICStream.name, () => {
const logger = new Logger(`${QUICStream.name} Test`, LogLevel.WARN, [
const logger = new Logger(`${QUICStream.name} Test`, LogLevel.INFO, [
new StreamHandler(
formatting.format`${formatting.level}:${formatting.keys}:${formatting.msg}`,
),
Expand Down