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

implement TLSSocket and connect from node:tls #3594

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

anonrig
Copy link
Member

@anonrig anonrig commented Feb 23, 2025

Work in progress. Not ready to review or land.

It's extremely early to even open this, but people have been asking about the progress, and what better way to show progress than the actual code (with a public pr)

@anonrig anonrig force-pushed the yagiz/introduce-tls branch 2 times, most recently from 1fb6373 to e77192f Compare February 24, 2025 01:28
Copy link

github-actions bot commented Feb 24, 2025

The generated output of @cloudflare/workers-types matches the snapshot in types/generated-snapshot 🎉

@cloudflare cloudflare deleted a comment from github-actions bot Feb 24, 2025
@danlapid
Copy link
Collaborator

Nice!
Glad to see this progressing!

@anonrig anonrig force-pushed the yagiz/introduce-tls branch 8 times, most recently from 7968547 to a8848ab Compare February 26, 2025 16:11
@anonrig anonrig force-pushed the yagiz/introduce-tls branch 11 times, most recently from 5c957db to 57490be Compare February 28, 2025 22:50
@anonrig anonrig marked this pull request as ready for review February 28, 2025 22:53
@anonrig anonrig requested review from a team as code owners February 28, 2025 22:53
@anonrig anonrig requested a review from erikcorry February 28, 2025 22:53
@anonrig anonrig requested a review from danlapid February 28, 2025 22:53
@anonrig anonrig force-pushed the yagiz/introduce-tls branch 3 times, most recently from b37c0b7 to ccbf33f Compare February 28, 2025 22:55
@anonrig anonrig force-pushed the yagiz/introduce-tls branch from ccbf33f to 30b394c Compare February 28, 2025 22:57
@anonrig anonrig force-pushed the yagiz/introduce-tls branch 3 times, most recently from c098331 to 9e499da Compare March 3, 2025 20:41
@anonrig anonrig force-pushed the yagiz/introduce-tls branch from 9e499da to 7da4321 Compare March 3, 2025 20:48
@anonrig anonrig force-pushed the yagiz/introduce-tls branch from 7da4321 to c07f938 Compare March 3, 2025 20:51
public [kPendingSession]: null | Buffer;
public [kErrorEmitted]: boolean;
public [kDisableRenegotiation]: boolean;
public [kPskCallback]?: TlsOptions['pskCallback'];
Copy link
Member

Choose a reason for hiding this comment

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

We know that we're not going to be supporting things like renegotiation and pre-shared key callbacks so I'm not sure it makes any sense to include these.

this.on('close', onSocketCloseDestroySSL);
}

wrap?.on('close', () => this.destroy());
Copy link
Member

Choose a reason for hiding this comment

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

once?

// Guard against adding multiple listeners, as this method may be called
// repeatedly on the same socket by reinitializeHandle
if (this.listenerCount('close', onSocketCloseDestroySSL) === 0) {
this.on('close', onSocketCloseDestroySSL);
Copy link
Member

Choose a reason for hiding this comment

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

once?

// Let's disable floating promises error.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
socket?._handle?.socket.opened.then(this._finishInit.bind(this));
socket?.on('error', onerror.bind(this));
Copy link
Member

Choose a reason for hiding this comment

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

once?

});
}

wrap?.on('error', (err: Error): void => {
Copy link
Member

Choose a reason for hiding this comment

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

once?

this._tlsOptions.handshakeTimeout > 0
)
this.setTimeout(0, this._handleTimeout.bind(this));
this.emit('secure');
Copy link
Member

Choose a reason for hiding this comment

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

Node.js will often emit events using process.nextTick(...) to defer execution. Is that needed on these?

// This means that options.host overrides a host arg.
if (listArgs[1] !== null && typeof listArgs[1] === 'object') {
Object.assign(options, listArgs[1]);
} else if (listArgs[2] !== null && typeof listArgs[2] === 'object') {
Copy link
Member

Choose a reason for hiding this comment

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

Fun fact... you don't need the !== null check here. Object.assign(options, null) is handled just fine. In fact, you could get by without any type check here.

this[kIsVerified] = true;
const session = this[kPendingSession];
this[kPendingSession] = null;
if (session) this.emit('session', session);
Copy link
Member

Choose a reason for hiding this comment

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

Another one... should these be wrapped in process.nextTick/queueMicrotask?

Comment on lines +40 to +45
try {
await once(socket, 'close');
fail(`close ${testName} should have thrown`);
} catch (err) {
strictEqual(err.name, 'AbortError');
}
Copy link
Member

Choose a reason for hiding this comment

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

Why not use assert.rejects()?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants