typegoose / mongodb-memory-server

Manage & spin up mongodb server binaries with zero(or slight) configuration for tests.
https://typegoose.github.io/mongodb-memory-server/
MIT License
2.56k stars 185 forks source link

fix(getport): Randomize first port using crypto #844

Closed noseworthy closed 8 months ago

noseworthy commented 8 months ago

The current implementation of getPort() relies on using Date.now()to get the first port to try to launch mongo on, even when the EXP_NET0LISTEN flag is set. This causes a couple issues:

In order to better randomize the initial port selection so that port conflicts can be avoided, instead of using Date.now() for an initial seed, use crypto.randomInt() which should provide more randomness and hopefully avoid some of these race conditions.

Related Issues

codecov[bot] commented 8 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (f5c7e27) 91.22% compared to head (b84c82a) 91.24%. Report is 3 commits behind head on master.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #844 +/- ## ========================================== + Coverage 91.22% 91.24% +0.01% ========================================== Files 15 15 Lines 1984 1988 +4 Branches 499 501 +2 ========================================== + Hits 1810 1814 +4 Misses 165 165 Partials 9 9 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

github-actions[bot] commented 8 months ago

:tada: This PR is included in version 9.1.5 :tada:

The release is available on:

Your semantic-release bot :package::rocket: