Skip to content

Conversation

@nbbeeken
Copy link
Collaborator

@nbbeeken nbbeeken commented Dec 3, 2025

Description

Continuation of the fail fast error changes. Our unconditional override of the lookup function makes CompassWeb's customization of lookup unusable by the socket layer.

Open Questions

Instead of respecting the custom option directly I was careful to still wrap the invocation in something that enforces verbatim to false. Do we prefer to just use lookup as is?

Checklist

"check": "npm run typecheck && npm run lint && npm run depcheck",
"check-ci": "npm run check",
"testonly": "nyc mocha --colors -r ts-node/register src/**/*.spec.ts",
"testonly": "nyc mocha --colors --register ts-node/register src/**/*.spec.ts",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Assertions were not pointing to the correct line in the tests without this change and the debugger would not stop on the breakpoint lines. -r is mocha's "require", not sure if that's the same as node's 🤔

# this is explicitly called as a dependency to make sure that is bootstrapped
# before mongodb-runner, since it is required via mongodb
- '@mongodb-js/saslprep'
- 'ts-node' # used by mocha
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I guess this relates to the -r change, but not sure how.

Comment on lines +591 to +599
const customLookup = mongoClientOptions.lookup;
// Adopt dns result order changes with Node v18 that affected the VSCode extension VSCODE-458.
// Refs https://github.com/microsoft/vscode/issues/189805
mongoClientOptions.lookup = (hostname, options, callback) => {
return dns.lookup(hostname, { verbatim: false, ...options }, callback);
return (customLookup ?? dns.lookup)(
hostname,
{ verbatim: false, ...options },
callback,
);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Suggested change
const customLookup = mongoClientOptions.lookup;
// Adopt dns result order changes with Node v18 that affected the VSCode extension VSCODE-458.
// Refs https://github.com/microsoft/vscode/issues/189805
mongoClientOptions.lookup = (hostname, options, callback) => {
return dns.lookup(hostname, { verbatim: false, ...options }, callback);
return (customLookup ?? dns.lookup)(
hostname,
{ verbatim: false, ...options },
callback,
);
// Adopt dns result order changes with Node v18 that affected the VSCode extension VSCODE-458.
// Refs https://github.com/microsoft/vscode/issues/189805
mongoClientOptions.lookup ??= (hostname, options, callback) => {
return dns.lookup(hostname, { verbatim: false, ...options }, callback);

This could also just be ??= if we want to use whatever lookup we are given, but it seems more correct to me that this package owns its opinion on the verbatim flag

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe also link to NODE-6437 given that passing the flag is a way to work around shortcomings of the driver, not something we should be doing here

Comment on lines +431 to +432
finalClientOptions.lookup('localhost', 27017, () => {}); // invoke it the way it would be by net/tls
expect(lookupSpy.getCalls()).to.have.lengthOf(1); // verify our input lookup was called instead of the dns package
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

bit of an odd test but since we're mocking things we don't actually get to the point where the driver would cause lookup to be invoked, by calling it here I'm checking that our input is wrapped rather than used directly.

@nbbeeken nbbeeken changed the title feat(devtools-connect): make lookup configurable feat(devtools-connect): make dns lookup configurable Dec 3, 2025
@nbbeeken nbbeeken changed the title feat(devtools-connect): make dns lookup configurable feat(devtools-connect): make dns lookup configurable COMPASS-9793 Dec 3, 2025
@coveralls
Copy link

Coverage Status

coverage: 77.955% (+4.3%) from 73.608%
when pulling 37c69c9 on COMPASS-9793-make-lookup-configurable
into ee947bf on main.

@nbbeeken nbbeeken merged commit 5d8fd40 into main Dec 3, 2025
33 checks passed
@nbbeeken nbbeeken deleted the COMPASS-9793-make-lookup-configurable branch December 3, 2025 19:21
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