[BUG]: API version cache never hits under a non-US locale: `instanceApiVersionLastRetrieved` is written with `toLocaleString()` and read with `Date.parse`, so every command runs the My Domain DNS check
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 74/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- javascript, node.js
调研方向
报告指出 Connection.retrieveMaxApiVersion() 和 getCachedApiVersion() 分别是写入和读取路径;首先在 CLI 或随附的 core 源码中定位这些方法及其测试。检查时间戳的写入和解析方式,然后为非美国 locale 添加测试。当 API 版本缓存能在不同 locale 下保持有效 24 小时,且重复执行命令时不会进行额外的 DNS 查询,即为完成。
由索引模型根据 Issue 内容生成。
描述
Before You Submit
- I'm using the latest version of Salesforce CLI
- I've searched the existing issues
- I've run
sf doctorto diagnose common issues
Related Issue
#3425 (the same API-version re-check path, for an org a command does not need; fixed in 2.123.1)
Command
any command that uses an org, e.g. sf data query -o <alias> -q "SELECT Id FROM Organization"
Org Type
Scratch Org
Did this work before?
Not sure
Last Working Version
No response
Summary
Connection.retrieveMaxApiVersion() caches the org's API version in the auth file with instanceApiVersionLastRetrieved: new Date().toLocaleString(), and getCachedApiVersion() reads that back with Date.parse(). toLocaleString() follows the process locale, and Date.parse() reads US-style dates. Under LANG=en_GB.UTF-8 the date is written 25/10/2026, 20:58:29, which parses to NaN, so the cache never hits.
So every command fetches the API version again, and first runs the My Domain DNS check (isResolvable() → MyDomainResolver, 3 s by default). One slow DNS answer then fails the command with DomainNotFoundError: The org cannot be found, though the org is fine: it stopped a three-hour test harness that makes an sf call about every ten seconds.
On the 1st to the 12th of a month, the same string parses with day and month swapped. Written on 10 May (10/05/2026), it reads as 5 October: in the future, so the cache does not expire for months. Written on 5 October (05/10/2026), it reads as 10 May, so it is always stale.
Repository to Reproduce
none needed: the root cause needs only node, and the effect any authenticated org.
Steps to reproduce
- The root cause, no org:
LANG=en_GB.UTF-8 node -e "const s=new Date(2026,9,25,20,58,29).toLocaleString(); console.log(s, Date.parse(s))" # 25/10/2026, 20:58:29 NaN LANG=en_GB.UTF-8 node -e "const s=new Date(2026,4,10,9,0,0).toLocaleString(); console.log(s, new Date(Date.parse(s)).toISOString())" # 10/05/2026, 09:00:00 2026-10-05T… (10 May read as 5 October) - The effect, with an org: run the same command twice per locale with debug logging. After each command, count the
Attempting to resolve urllines the day's log gained:L=~/.sf/sf-$(date +%Y-%m-%d).log for loc in en_GB.UTF-8 en_GB.UTF-8 en_US.UTF-8 en_US.UTF-8 en_GB.UTF-8 en_GB.UTF-8; do b=$(grep -c "Attempting to resolve url" $L) LANG=$loc SF_LOG_LEVEL=debug sf data query -o <alias> -q "SELECT Id FROM Organization" --json > /dev/null echo "$loc $(( $(grep -c "Attempting to resolve url" $L) - b )) lookups; cache: $(jq -r .instanceApiVersionLastRetrieved ~/.sfdx/<username>.json)" done
Expected Result
After the first command, the API version comes from the cache for 24 hours, whatever the locale, and no DNS check runs.
Actual Result
Measured 2026-10-25 on 2.155.7 with the loop above, against a scratch org:
en_GB.UTF-8 2 lookups; cache: 25/10/2026, 23:24:04
en_GB.UTF-8 2 lookups; cache: 25/10/2026, 23:24:06
en_US.UTF-8 1 lookups; cache: 10/25/2026, 11:24:07 PM
en_US.UTF-8 0 lookups; cache: 10/25/2026, 11:24:07 PM
en_GB.UTF-8 0 lookups; cache: 10/25/2026, 11:24:07 PM
en_GB.UTF-8 0 lookups; cache: 10/25/2026, 11:24:07 PM
Under en_GB, every command looks the org up twice and rewrites the cache date. Once an en-US date is written, en_GB reads it, until the 24 hours run out and the date is written in GB form again.
Error Message
What one slow DNS answer does to a command that runs the check. Here the slow answer is simulated: a --require hook delays dns.lookup of the org's host by 5 s, and SFDX_IGNORE_API_VERSION_CACHE=true makes the check run as the locale bug does. The real slow answer, on 2.138.6, stopped an sf project deploy start with the same error.
$ SFDX_IGNORE_API_VERSION_CACHE=true sf data query -o <alias> -q "SELECT Id FROM Organization"
Error (DomainNotFoundError): Parsing --target-org
The org cannot be found
Workaround: SFDX_DNS_TIMEOUT=30 (the same call: exit 0 after 22 s, the record returned). Not SF_DNS_TIMEOUT, which does nothing: see Additional Information.
System Information
{
"architecture": "linux-x64",
"cliVersion": "@salesforce/cli/2.155.7",
"nodeVersion": "node-v24.14.0",
"osVersion": "Linux 6.8.0-93260105-generic",
"rootPath": "<cut>",
"shell": "bash",
"pluginVersions": [
"@oclif/plugin-autocomplete 4.0.4 (core)",
"@oclif/plugin-commands 5.0.4 (core)",
"@oclif/plugin-help 7.0.4 (core)",
"@oclif/plugin-not-found 4.0.4 (core)",
"@oclif/plugin-plugins 7.0.7 (core)",
"@oclif/plugin-search 2.0.0 (core)",
"@oclif/plugin-update 5.0.4 (core)",
"@oclif/plugin-version 3.0.5 (core)",
"@oclif/plugin-warn-if-update-available 4.0.3 (core)",
"@oclif/plugin-which 4.0.4 (core)",
"@salesforce/cli 2.155.7 (core)",
"agent 2.2.2 (core)",
"apex 4.4.3 (core)",
"api 2.0.17 (core)",
"auth 5.0.16 (core)",
"data 5.1.16 (core)",
"deploy-retrieve 4.2.14 (core)",
"info 4.0.16 (core)",
"limits 4.0.6 (core)",
"marketplace 2.0.17 (core)",
"org 6.0.26 (core)",
"packaging 3.0.14 (core)",
"schema 4.0.12 (core)",
"settings 3.0.14 (core)",
"sobject 2.0.12 (core)",
"telemetry 4.2.0 (core)",
"templates 57.4.6 (core)",
"trust 4.0.20 (core)",
"user 5.0.11 (core)"
]
}
Additional Information
- Suggested fix: write the date as
new Date().toISOString().Date.parse()reads ISO 8601 in every locale. A date already written in the old form is replaced the next time it reads as stale, but one that parsed into the future holds until that date. SF_DNS_TIMEOUTis ignored. SettingSFDX_DNS_TIMEOUTmakes sf warn "Deprecated environment variable: SFDX_DNS_TIMEOUT. Please use SF_DNS_TIMEOUT instead.", butsrc/status/myDomainResolver.tsreads onlynew Env().getNumber('SFDX_DNS_TIMEOUT', 3). WithSF_DNS_TIMEOUT=30and noSFDX_DNS_TIMEOUT, the Error Message call above fails at 7.3 s, as with neither set. Measured on 2.155.7 and 2.138.6. So following the warning puts the timeout back to 3 s, and nothing says so.- Node's default locale (ICU) follows
LC_ALL, thenLC_MESSAGES, thenLANG.LC_TIMEalone does not change it. Not measured on macOS or Windows. - Ubuntu 24.04.3 LTS, bash,
LANG=en_GB.UTF-8. Bundled@salesforce/core9.3.6. Also seen on 2.138.6 (core 8.31.0). Also seen against a production Dev Hub, not only scratch orgs.
Screenshots or Log Files
No response
- 主要语言
- 没有语言数据
- 星标
- 571
- 派生
- 80
- 平均合并
- 14 小时 43 分钟
- 30 天内合并 PR
- 5
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
forcedotcom/cli 的其他 Issue
-
sf agent mcp asset replace --assets null throws raw TypeError instead of InvalidShape可能已有人在做 @konkonrong-lgtm 于 77 天前认领。 未关闭area:afdx bug investigating owned by another team validated
难度 2/5 1-3 小时 新手友好度 78/100
forcedotcom/cli#3625 · 4 条评论 ·
-
area:afdx bug owned by another team
难度 2/5 1-3 小时 新手友好度 78/100
forcedotcom/cli#3608 · 2 条评论 ·
-
难度 3/5 1-2 天 新手友好度 68/100
forcedotcom/cli#3670 · 1 条评论 ·
-
announcement
难度 1/5 1 小时以内 新手友好度 1/100
forcedotcom/cli#3668 ·
-
bug investigating validated
难度 3/5 1-2 天 新手友好度 66/100
forcedotcom/cli#3667 · 5 条评论 ·
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
nebari-dev/nebi#630 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
router-for-me/CLIProxyAPI#7084 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 83/100
speakeasy-api/openapi#284 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
jwage/phpamqplib-messenger#159 ·