-
Notifications
You must be signed in to change notification settings - Fork 8
feat(devtools-proxy-support): initial shared implementation COMPASS-8072 #418
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
Conversation
There was a problem hiding this 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 😅
while (this._reqLock) { | ||
await this._reqLock; | ||
} |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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 🙂
There was a problem hiding this comment.
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 👍
Co-authored-by: Sergey Petushkov <[email protected]>
|
||
// 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> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥
There was a problem hiding this 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! 😍
A few things small that might be helpful for reviewing this PR:
Some potentially helpful reading:
CONNECT
proxiesPAC (proxy auto-config) files
Agent
is a connection/socket factory)proxy-agent
package READMEThis PR will replace:
@mongosh/import-node-fetch
in mongosh@mongodb-js/ssh-tunnel
in Compass (split into two things,SSHAgent
andSocks5Server
)I'd recommend starting with
proxy-options.ts
andagent.ts
and their associated test files, then work onwards from there.