Skip to content

Fix undefined array key "port" warning from partial host config in APCu cache - #271

Draft
MelvinBot wants to merge 1 commit into
mainfrom
claude-fixBedrockUndefinedPortWarning
Draft

Fix undefined array key "port" warning from partial host config in APCu cache#271
MelvinBot wants to merge 1 commit into
mainfrom
claude-fixBedrockUndefinedPortWarning

Conversation

@MelvinBot

Copy link
Copy Markdown
Contributor

Explanation of Change

Fixes a benign-but-noisy PHP Warning: Undefined array key "port" emitted from Client::getPossibleHosts().

When a Bedrock host connection fails, markHostAsFailed() did $hostConfigs = apcu_fetch($apcuKey) and then unconditionally wrote $hostConfigs[$host]['blacklistedUntil'] = .... If apcu_fetch() returned false (cold cache after a deploy/eviction, or a concurrent worker having just reset it), PHP auto-vivified a host entry containing only blacklistedUntil and no port, and stored it back into APCu. A later getPossibleHosts() iterated the cached configs and read $config['port'] unconditionally, tripping the warning.

This change makes both sides defensive:

  • markHostAsFailed() now only updates an entry that already exists (is_array($hostConfigs) && isset($hostConfigs[$host])), so it never writes a partial host config missing port. If the cache is cold, getPossibleHosts() repopulates it with full configs on its next call.
  • getPossibleHosts() reads $config['port'] ?? null, so even a partial entry written by an older worker no longer warns — the null simply forces the existing cache-mismatch reset path.

The warning was cosmetic (the originating request completed 200 OK) and self-healing, but it trips BugBot as a staging deploy blocker.

Related Issues

https://github.com/Expensify/Expensify/issues/667952

Deployment

  • I followed the steps in the README to ensure this PR is deployed properly

Co-authored-by: Puneet Lath <puneetlath@users.noreply.github.com>
@MelvinBot
MelvinBot requested a review from a team August 18, 2026 15:29
@puneetlath

Copy link
Copy Markdown

@MelvinBot can you merge main into this PR?

Comment thread src/Client.php
Comment on lines +677 to +678
// A cached entry may be missing its 'port' (e.g. a partial config written by an older worker). Treat
// it as null so the comparison below detects the mismatch and resets the cache, rather than warning.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MelvinBot can you udpate these comments so each sentence is on its own line. Rather than having the second sentence split by lines.

Comment thread src/Client.php
Comment on lines +898 to +900
// Only update an entry that already exists so we don't auto-vivify a partial host config (one without a
// 'port') when the cache is cold or was just reset by a concurrent worker. getPossibleHosts will
// repopulate the cache with full configs on its next call.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MelvinBot can you make this comment more succinct?

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