Last 12 weeks ยท 0 commits
4 of 6 standards met
Repository: sindresorhus/get-port. Description: Get an available TCP port Stars: 925, Forks: 66. Primary language: JavaScript. Languages: JavaScript (95.2%), TypeScript (4.8%). License: MIT. Latest release: v7.1.0 (1y ago). Open PRs: 0, open issues: 1. Last activity: 5mo ago. Community health: 85%. Top contributors: sindresorhus, jonahsnider, nagen010, acostalima, arthurvr, coreyfarrell, sinterstice, davidmarkclements, BendingBender, mastrzyz and others.
Hello, I have an issue. The code is: With version 4.2.0 the output is as expected With ^5.0.0, however, the second time I'm requesting the port, it comes out 1 more than before: Has anyone here encountered this issue or knows any way to solve it?
Summary It is assumed that there is a race condition relevant to this line: https://github.com/sindresorhus/get-port/blob/5c3cfe828bac345fb30b13211164708d97cb033a/index.js#L134 when the user sends a preferred port range (via the param). Analysis 1. Assuming that the user has previously called and acquired some available ports within the range. 2. Assuming that the loop at this line would iterate over the already-assigned ports. 3. Notice that at this line comes before the check, it would indeed proceed to the point where it attempts to bind to that port. 4. Assuming that the user then attempts to bind to the port, which is in use by . Therefore the race condition would be triggered. A PoC Sample code: Sample invocation (as of v7.1.0): Proposed fix ~Just to check against the assignment records () before attempting to bind to a non-zero port.~ Edit:** Hmm sorry that might not look that straightforward as there seem to be other possible causes of race conditions as well.