Skip to content

Conversation

addaleax
Copy link
Collaborator

@addaleax addaleax commented Jul 18, 2024

A few things small that might be helpful for reviewing this PR:

Some potentially helpful reading:

This PR will replace:

I'd recommend starting with proxy-options.ts and agent.ts and their associated test files, then work onwards from there.

@addaleax addaleax added the wip label Jul 18, 2024
@addaleax addaleax changed the title [WIP] feat(devtools-proxy-support): initial shared implementation COMPASS-8072 feat(devtools-proxy-support): initial shared implementation COMPASS-8072 Jul 25, 2024
@addaleax addaleax removed the wip label Jul 25, 2024
@addaleax addaleax marked this pull request as ready for review July 25, 2024 12:06
Copy link
Collaborator

@gribnoysup gribnoysup left a comment

Choose a reason for hiding this comment

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

I left some small nits and one question just for my understanding, otherwise it looks good, but it's a lot of code, so I definitely might've missed some things 😅

Comment on lines +82 to +84
while (this._reqLock) {
await this._reqLock;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just curious why we are using while here: is there a possibility of a microtask happening between await resolving and the execution going to the beginning of the loop to check the _reqLock?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

is there a possibility of a microtask happening between await resolving and the execution going to the beginning of the loop to check the _reqLock?

The await here does always wait at least one microtask queue iteration, and during that iteration other things can happen (such as other Promises being resolved and handlers for that resolution running)

Just curious why we are using while here

Yeah, it's to avoid a scenario where if .connect() gets called twice (or more) in a synchronous code block, both of those .connect() calls would await the same _reqLock Promise and then simultaneously proceed (and each of them create new, independent _reqLock promises, overwriting each other)

Copy link
Collaborator

@gribnoysup gribnoysup Jul 31, 2024

Choose a reason for hiding this comment

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

Aha, got it, thanks for a detailed explanation with an example, it like made sense, but was still hard to wrap my head around the details of the flow without it

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah ... it didn't feel worth pulling in an external library for this, but if you feel like that would be a good idea to make it more obvious what's happening here, I am not opposed to that at all (because it's not just you, I also had to give this a bit of thought to be confident that it's correct the way it is)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it's good as is! If you want to add some sort of comment in the code for this (like this example you provided I think made it very clear for me what this is guarding against), it would be enough I think, but even without it, it's fine, if it raises questions at the very least it will be possible to track it to this conversation now 🙂

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure, added a small comment about this as well 👍


// The original version of this code was largely taken from
// https://github.com/mongodb-js/mongosh/blob/8e6962432397154941f593c847d8f774bfd49f1c/packages/import-node-fetch/src/index.ts
async function importNodeFetch(): Promise<typeof fetch> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

🔥

Copy link
Collaborator

@alenakhineika alenakhineika left a comment

Choose a reason for hiding this comment

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

Wow Anna, this is amazing! I rely more on your tests than my eyes 😄 but did my best reading through your changes a couple of times and don't see anything else except these comments I have already left. Great work! 😍

@addaleax addaleax merged commit 39d4fb7 into main Aug 1, 2024
5 checks passed
@addaleax addaleax deleted the 8072-dev branch August 1, 2024 09:10
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.

3 participants