-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: use setTimeout Promise #58
Conversation
Warning Rate limit exceeded@fengmk2 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 17 minutes and 44 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (1)
WalkthroughThe changes in this pull request involve the introduction of a custom Changes
Possibly related PRs
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (2)
src/wait-port.ts (2)
6-10
: Consider using built-insetTimeout
from node:timers/promisesThe custom
sleep
implementation, while functional, appears to be replacing the built-insetTimeout
fromnode:timers/promises
which is a stable API since Node.js 15.0.0. What's the rationale for this change?If we must keep the custom implementation, consider adding input validation:
function sleep(ms: number) { + if (ms < 0) throw new Error('Sleep duration must be non-negative'); return new Promise(resolve => { setTimeout(resolve, ms); }); }
Line range hint
39-44
: Consider potential race condition in port verificationThere's a potential race condition in the retry logic. After detecting a free port and sleeping, the port's status might change before the next iteration. Consider verifying the port status both before and after the sleep:
const freePort = await detectPort(port); if (freePort === port) { await sleep(retryInterval); + // Re-verify port status after sleep + const currentPort = await detectPort(port); + if (currentPort !== port) { + return true; + } return loop(); } return true;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Outside diff range and nitpick comments (3)
.github/workflows/nodejs-14.yml (3)
5-5
: Consider usingmain
instead ofmaster
GitHub now recommends using
main
as the default branch name instead ofmaster
for inclusive language.- branches: [ master ] + branches: [ main ]Also applies to: 7-7
19-20
: Add npm dependency cachingAdding cache for npm dependencies will speed up the workflow execution.
Add this step before
npm install
:- name: Cache node modules uses: actions/cache@v3 with: path: ~/.npm key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} restore-keys: | ${{ runner.os }}-node-
21-23
: Simplify Node.js version verificationThe current approach of checking Node.js version before and after switching seems redundant. Consider combining these steps.
- - run: node -v - - run: nvm install 14 && nvm use 14 - - run: node -v + - name: Switch to Node.js 14 + run: | + nvm install 14 && nvm use 14 + echo "Using Node.js $(node -v)"
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
.github/workflows/nodejs-14.yml
(1 hunks)
🔇 Additional comments (1)
.github/workflows/nodejs-14.yml (1)
1-24
: Verify setTimeout Promise compatibility with Node.js 14
Since this workflow tests Node.js 14 compatibility and the PR changes involve Promise-based setTimeout, we should verify the implementation works correctly.
✅ Verification successful
Let me check the implementation details of the setTimeout usage to ensure it's Node.js 14 compatible.
Node.js 14 compatibility is properly maintained
The setTimeout implementation in the codebase is using the standard callback-based approach which is fully compatible with Node.js 14:
- Uses traditional Promise constructor with callback-based setTimeout in
sleep
function - No usage of
node:timers/promises
or Promise-based setTimeout - Test cases also use standard setTimeout with callbacks
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Check if the codebase uses node:timers/promises which is not available in Node.js 14
rg -l "node:timers/promises" || echo "No direct usage of node:timers/promises found"
# Check for setTimeout Promise usage
ast-grep --pattern 'setTimeout($$$)'
Length of output: 359
Script:
#!/bin/bash
# Check the implementation of wait-port.ts
cat src/wait-port.ts
# Check the test file
cat test/wait-port.test.ts
Length of output: 2426
.github/workflows/nodejs-14.yml
Outdated
- run: npm install | ||
- run: npm run prepublishOnly | ||
- run: node -v | ||
- run: nvm install 14 && nvm use 14 | ||
- run: node -v | ||
- run: node dist/commonjs/bin/detect-port.js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add explicit test step
The workflow is missing an explicit test step. While prepublishOnly
might run tests, it's better to have a dedicated test step for clarity.
Add this step after prepublishOnly
:
- name: Run tests
run: npm test
.github/workflows/nodejs-14.yml
Outdated
- run: node -v | ||
- run: nvm install 14 && nvm use 14 | ||
- run: node -v | ||
- run: node dist/commonjs/bin/detect-port.js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add error handling for detect-port binary execution
The workflow should handle potential failures when running the detect-port binary and provide meaningful error output.
- - run: node dist/commonjs/bin/detect-port.js
+ - name: Test detect-port binary
+ run: |
+ set -e
+ if ! output=$(node dist/commonjs/bin/detect-port.js 2>&1); then
+ echo "Error running detect-port: $output"
+ exit 1
+ fi
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
- run: node dist/commonjs/bin/detect-port.js | |
- name: Test detect-port binary | |
run: | | |
set -e | |
if ! output=$(node dist/commonjs/bin/detect-port.js 2>&1); then | |
echo "Error running detect-port: $output" | |
exit 1 | |
fi |
uses: irby/setup-node-nvm@master | ||
with: | ||
node-version: '16.x' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider using the official Node.js setup action
The workflow uses irby/setup-node-nvm@master
which is a third-party action. For better security and reliability, consider using the official actions/setup-node
action which also supports multiple Node.js versions.
- uses: irby/setup-node-nvm@master
+ uses: actions/setup-node@v4
with:
- node-version: '16.x'
+ node-version: ['14.x', '16.x']
Committable suggestion skipped: line range outside the PR's diff.
[skip ci] ## [2.0.1](v2.0.0...v2.0.1) (2024-12-08) ### Bug Fixes * use setTimeout Promise ([#58](#58)) ([db3ce1b](db3ce1b))
Summary by CodeRabbit
New Features
Bug Fixes