Skip to content

Keep host and password when the legacy port argument is unset - #78

Open
freshlogic wants to merge 1 commit into
v5.0.0from
v6-constructor-fix
Open

freshlogic wants to merge 1 commit into
v5.0.0from
v6-constructor-fix

Conversation

@freshlogic

Copy link
Copy Markdown
Member

The bug

v5.0.0's constructor dispatches the legacy (port, host, options) signature on the port argument alone. Every production caller passes:

new PettyCache(process.env.redisPort, process.env.redisHost, { auth_pass: ..., enable_offline_queue: false })

and redisPort is not set on any App Service — verified in meh-com's app settings, which carry redisHost and redisPassword and no port. So undefined fails isPort(), fails the arguments[0] && typeof === 'object' check, and lands in the final else as redis.createClient(undefined).

Measured against the branch head (8d2f7b0) with the fleet's exact call shape:

(undefined, host, {auth_pass, enable_offline_queue})  host=undefined port=undefined pass=MISSING offlineQ=undefined
('', host, {auth_pass})                               host=undefined port=undefined pass=MISSING offlineQ=undefined

Host, password and the offline-queue setting all discarded, leaving an unauthenticated client pointed at localhost:6379. It does not throw. Every site would lose its cache at once on upgrade.

The existing tests cannot catch it — they all pass a literal port (6379 or '6379'), and CI runs against a passwordless localhost Redis where a misconfigured client still connects.

The fix

Dispatch on arity as well as port type, and let node-redis apply its own port default when the given one is unusable, rather than discarding everything that follows it.

After:

(undefined, host, {auth_pass, enable_offline_queue})  host=redis.example.net port=undefined pass=SET offlineQ=true
('', host, {auth_pass})                               host=redis.example.net port=undefined pass=SET offlineQ=undefined
('6380', host, {auth_pass})                           host=redis.example.net port=6380   pass=SET offlineQ=undefined
(6379, host, {auth_pass})                             host=redis.example.net port=6379   pass=SET offlineQ=undefined
(6379, host)                                          host=localhost        port=6379    pass=MISSING
()                                                    host=undefined        port=undefined pass=MISSING

Tests

One regression test covering the unset and empty-string port cases, asserting host and password survive. 176/176 pass, eslint clean.

🤖 Generated with Claude Code

The constructor dispatched the legacy (port, host, options) signature on the
port alone. Production callers pass process.env.redisPort, which is not set on
any App Service, so undefined missed both the port branch and the options
branch and fell through to createClient(undefined) -- discarding the host, the
password and the offline-queue setting, and leaving an unauthenticated client
pointed at localhost.

Dispatch on arity as well, and let node-redis apply its own port default when
the given one is unusable. The existing tests could not catch this because they
all pass a literal port, and CI runs against a passwordless localhost Redis.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 33523055812

Warning

No base build found for commit 8d2f7b0 on v5.0.0.
Coverage changes can't be calculated without a base build.
If a base build is processing, this comment will update automatically when it completes.

Coverage: 100.0%

Details

  • Patch coverage: 10 of 10 lines across 1 file are fully covered (100%).

Uncovered Changes

No uncovered changes found.

Coverage Regressions

Requires a base build to compare against. How to fix this →


Coverage Stats

Coverage Status
Relevant Lines: 1013
Covered Lines: 1013
Line Coverage: 100.0%
Relevant Branches: 277
Covered Branches: 277
Branch Coverage: 100.0%
Branches in Coverage %: Yes
Coverage Strength: 54.41 hits per line

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants