fix(nim): resolve host port dynamically in nimStatusByName()#1068
fix(nim): resolve host port dynamically in nimStatusByName()#1068latenighthackathon wants to merge 3 commits intoNVIDIA:mainfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughUpdated Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
bin/lib/nim.js (1)
204-208: Consider adding port validation to handle unexpecteddocker inspectoutput.The code at line 207 relies on
|| "8000"to handle missing port mappings, but this only catches falsy values. Ifdocker inspectunexpectedly returns non-numeric text (though unlikely with the deterministicdocker inspect --formattemplate),Number(hostPort)could produceNaNat line 208, causing an invalid health-check URL.Since
runCapturealready trims output and missing port mappings are caught by the fallback, the actual risk is low. However, adding a simple regex check makes the code more robust:Optional hardening patch
- const hostPort = runCapture( + const rawHostPort = runCapture( `docker inspect --format '{{(index (index .NetworkSettings.Ports "8000/tcp") 0).HostPort}}' ${shellQuote(name)} 2>/dev/null`, { ignoreError: true } - ) || "8000"; - const health = runCapture(`curl -sf http://localhost:${Number(hostPort)}/v1/models 2>/dev/null`, { + ); + const hostPort = /^\d+$/.test(rawHostPort) ? rawHostPort : "8000"; + const health = runCapture(`curl -sf http://localhost:${hostPort}/v1/models 2>/dev/null`, { ignoreError: true, });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@bin/lib/nim.js` around lines 204 - 208, The hostPort returned by runCapture may be non-numeric; validate it before using Number(hostPort) in the health curl call. After computing hostPort (from runCapture or fallback "8000"), test it with a regex or parseInt+isFinite (e.g., ensure /^\d+$/.test(hostPort) or Number.isFinite(parsed) ) and if invalid fall back to 8000; then use the validated numericPort variable in the runCapture used to compute health. Update references to hostPort/Number(hostPort) so health uses the validated port value.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@bin/lib/nim.js`:
- Around line 204-208: The hostPort returned by runCapture may be non-numeric;
validate it before using Number(hostPort) in the health curl call. After
computing hostPort (from runCapture or fallback "8000"), test it with a regex or
parseInt+isFinite (e.g., ensure /^\d+$/.test(hostPort) or
Number.isFinite(parsed) ) and if invalid fall back to 8000; then use the
validated numericPort variable in the runCapture used to compute health. Update
references to hostPort/Number(hostPort) so health uses the validated port value.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 6d36cc1b-4259-47d5-b516-8b2f1428a582
📒 Files selected for processing (1)
bin/lib/nim.js
nimStatusByName() hardcoded port 8000 for the health check curl, but the host port is configurable via startNimContainer(). Containers started on a custom port would always report unhealthy. Use docker inspect to read the actual host port mapping from the container's NetworkSettings before probing the /v1/models endpoint. Closes NVIDIA#1016
Add regex validation so unexpected docker inspect output (non-numeric text) falls back to port 8000 instead of producing a NaN URL. Addresses CodeRabbit review nitpick.
94ce221 to
966f0b7
Compare
|
Thanks for working on this. I reviewed I don’t think we should merge both. Your PR does address the underlying hardcoded-port bug, but
Because of that, I think the right outcome is to take |
|
Closing this in favor of #1022, which covers the same |
Summary
nimStatusByName() hardcoded port 8000 for health checks, but the host port is configurable. Containers on custom ports always reported unhealthy. Now uses docker inspect to resolve the actual host port mapping.
Related Issue
Closes #1016
Changes
Type of Change
Testing
npx prek run --all-filespasses (or equivalentlymake check).npm testpasses.make docsbuilds without warnings. (for doc-only changes)Checklist
General
Code Changes
Summary by CodeRabbit