Skip to content

Conversation

@gagik
Copy link
Collaborator

@gagik gagik commented Oct 10, 2025

Should help in cases where multiple processes are trying to download Mongo binaries.

@gagik gagik changed the title chore(mongodb-downloader): use a lockfile to prevent redundant parallel downloads MONGOSH-1875 feat(mongodb-downloader)!: use a lockfile to prevent redundant parallel downloads MONGOSH-1875 Oct 10, 2025
Object.create(null);

// Download mongod + mongos and return the path to a directory containing them.
async downloadMongoDbWithVersionInfo(
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 know this is kind of a big breaking change... I am open to refactoring back but this should relatively simple migration generally and in my opinion a general improvement.

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 see the lockfile part as also a big "breaking" change (unless we make it opt-in) so I kind of see an opportunity to do this now

Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess I'm not really clear on what we get out of changing the public interface of this package?

Like, the class as a code organization tool is perfectly fine, but if we're already worrying about cross-process download interactions (which we should!), is it still worth exposing this to users of this package as a way to worry about in-process download interactions?

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 that is totally fair re: public interface. The original motivation for changing the public interface came from the initial approach which was "locking" in-memory inside the class so then the instance being managed would be up to the user. Obviously with the file-based approach this is irrelevant.

So I'll keep the class refactor for sake of code organization if that sounds good but keep the old API.

Copy link
Collaborator Author

@gagik gagik Oct 20, 2025

Choose a reason for hiding this comment

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

Re: opting in/out,
opt-in seems safest in terms of not breaking workflows so I'll do this for now. I can make this a required property so projects can decide and discover this functionality easily. so it'd be a breaking change but very explicitly about this.

@gagik gagik force-pushed the gagik/download-dir branch from fa16082 to 20e4664 Compare October 10, 2025 16:31
// Adapted from:
// https://raw.githubusercontent.com/npm/cli/072253549d774893a3689341dbc660cb845ebcfe/workspaces/libnpmexec/lib/with-lock.js

// The Artistic License 2.0
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 Author

Choose a reason for hiding this comment

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

ah, that's a good doc to have on hand. Welp, I guess I'll use proper-lockfile

@gagik gagik marked this pull request as draft October 20, 2025 13:07
const controller = new AbortController();
let release: (() => Promise<void>) | undefined;

const lockFile = `${originalFilePath}/.mongodb-downloader-lock`;
Copy link
Collaborator Author

@gagik gagik Oct 21, 2025

Choose a reason for hiding this comment

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

this is annoying but actually proper lockfile expects an existing file to create a lock around, so we'll have both .mongodb-downloader-lock and .mongodb-downloader-lock.lock...
so this dummy file actually does nothing, it's .mongodb-downloader-lock.lock that is relevant.

I can't do it on i.e. mongod since it's existence is used to figure out if the file is actually downloaded. alternatively, I could create a dummy mongod with some flag to it to differentiate

});
});

describe('version name', function () {
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 tried to untangle the version resolution stuff and adding these to make sure this is the expected output

@gagik gagik marked this pull request as ready for review October 22, 2025 14:45
Copy link
Collaborator

@addaleax addaleax left a comment

Choose a reason for hiding this comment

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

🚀

@gagik gagik merged commit 18d079a into main Oct 24, 2025
6 of 7 checks passed
@gagik gagik deleted the gagik/download-dir branch October 24, 2025 15:34
gagik added a commit to mongodb-js/mongosh that referenced this pull request Oct 24, 2025
This is making use of the new locking mechanism with the runner and downloader in mongodb-js/devtools-shared#580
as well as having a single place for all binaries.
gagik added a commit to mongodb-js/mongosh that referenced this pull request Oct 24, 2025
This is making use of the new locking mechanism with the runner and downloader in mongodb-js/devtools-shared#580
as well as having a single place for all binaries.
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.

2 participants