You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(getport): randomize first port using crypto.randomInt (#844)
* fix(getport): Randomize first port using crypto
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:
- If the `Date` module is mocked, it can result in `getFreePort()`
returning the same first port every time.
- If multiple mongos are being started at once in parallel, it's
possible for the same first port to be picked leading to port
conflicts
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.
re #827
* fix(getport): change crypto.randomInt "max" to be inclusive
---------
Co-authored-by: hasezoey <[email protected]>
0 commit comments