GTM fails to start on machines with <= 2 CPUs: "binding threads failed" (empty cpuset in bind_service_threads)
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 74/100
Research direction
Start in src/gtm/main/main.c with bind_service_threads() and bind_timekeeper_thread(), then read bind_thread_to_cores() to understand how affinity failures are handled. Reproduce with one or two CPUs using the commands in the issue. Done means GTM starts successfully in those cases, skipping an empty affinity set and using CPU 0 for the timekeeper on a single-core machine.
Written by the indexing model from the issue text.
Description
环境
- OpenTenBase master(
b2b129b) - 任意 Linux,1 或 2 个 CPU 核(虚拟机限核或
taskset -c 0,1均可复现)
现象
GTM 启动即失败,报:
[src/gtm/main/main.c:2216] binding threads failed for 22
之后进程退出(部分版本表现为 FATAL: binding threads failed)。README 的「常见错误与排查」已记录该现象:
README.md:462 —— "GTM startup reports FATAL: binding threads failed (typically on machines with ≤ 2 CPU cores)",目前只有 noaffinity.so + /etc/ld.so.preload 的 workaround。
复现步骤
nproc # 1 或 2
initgtm -D /tmp/gtm_data
gtm -D /tmp/gtm_data -p 6666
预期 GTM 正常监听;实际在 bind_service_threads() 处失败退出。
根因分析(源码)
src/gtm/main/main.c:
void bind_service_threads(void)
{
int cpu_num = get_nprocs();
int cpu;
cpu_set_t cpuset;
CPU_ZERO(&cpuset);
for(cpu = 2; cpu < cpu_num; cpu++) // 2 核时循环不执行,cpuset 为空
{
CPU_SET(cpu, &cpuset);
}
bind_thread_to_cores(cpuset); // 空 cpuset -> pthread_setaffinity_np 返回 EINVAL
}
bind_thread_to_cores()(main.c:2208-2218)对失败直接 elog(ERROR, "binding threads failed for %d", r),没有降级路径;
bind_timekeeper_thread()(main.c:2220-2234)在单核机器上 CPU_SET(1, &cpuset) 同样会失败(只有 0 号核可用)。
期望行为
CPU 亲和性绑定属于性能优化,不应导致 GTM 启动失败:
cpuset为空或pthread_setaffinity_np返回EINVAL时,记录 WARNING 后跳过绑定,继续启动;- timekeeper 在单核机器上回退到 CPU 0。
补充说明
已在 master b2b129b 上确认代码路径;仓库中没有与此对应的 issue/PR("binding threads failed" 仅在 PR #213 的文档改动中出现)。如果需要,我可以补充在 1–2 核环境下的完整启动日志。
- Dominant language
- C
- Stars
- 946
- Forks
- 693
- Avg merge
- 5m
- Merged PRs (30d)
- 1
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from OpenTenBase/OpenTenBase
-
otb-health: 健康检查永远以退出码 0 结束,检查失败无法被发现Possibly taken @shibuchou claimed this 20 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
OpenTenBase/OpenTenBase#503 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 1-3 hours Newbie friendliness 72/100
OpenTenBase/OpenTenBase#319 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 45/100
OpenTenBase/OpenTenBase#541 ·
Maintainers usually reply within 1 day
-
7Open
Difficulty 5/5 Over a week Newbie friendliness 15/100
OpenTenBase/OpenTenBase#524 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
OpenTenBase/OpenTenBase#522 ·
Maintainers usually reply within 1 day
All issues in OpenTenBase/OpenTenBase
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
libsdl-org/SDL#16837 ·
Maintainers usually reply within 1 day
-
Claude:NeedsReview GPT:ConfirmedBug GPT:NeedsReview triage
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
open5gs/open5gs#5141 · 2 comments ·
Maintainers usually reply within 1 day
-
CI: MSYS2 jobs fail — mingw python3 package renamed upstream to pythonPossibly taken @ronaldtse claimed this today. Open
Difficulty 1/5 Under an hour Newbie friendliness 95/100
-
bug good first issue
Difficulty 1/5 Under an hour Newbie friendliness 85/100
TanvirHasanAkash/CSE114-Lab-Project-72_B2_G2#37 ·
Maintainers usually reply within 1 day
-
issue: bug report
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 2 days