端口漂移:默认开启,端口被占用时自动换端口启动
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 55/100
Research direction
Start by locating the server startup path that currently calls ListenAndServe, the configuration handling for OIS_PORT_DRIFT, and the self-check command. Read the existing startup and error handling, then add focused tests for occupied ports, :0, non-occupied errors, and the disabled setting. Done means startup logs show the original and selected addresses and attempts, and the README configuration table documents the default-on switch.
Written by the indexing model from the issue text.
Description
背景
服务端口被占用时进程直接启动失败。本地多服务并存(或残留进程未退出)时经常撞端口。参考需求:open-pdf 已实现的端口漂移机制。
需求
- 默认开启端口漂移:配置端口被占用时自动尝试后续端口(步进 +1,最多尝试 20 个),每次尝试记 info 日志,成功后以醒目日志输出最终监听地址(含漂移前的原地址)
- 支持关闭:
OIS_PORT_DRIFT=false时保持现状——端口被占立即报错退出,错误为 5xxx 稳定错误码(含「端口被占用」人话提示与原地址) - 边界行为:
- 端口为
:0(系统随机分配)不做漂移 - 非「占用」类错误(权限不足、地址不可用等)不漂移,原样报错
- 连续 20 个端口全部失败:报稳定错误码退出,日志列出尝试范围
- 端口为
- 容器形态不受影响(独立网络命名空间);
self-check子命令仍探测配置端口 - README 配置表补充该开关与默认值
技术要点
- 用
net.Listen探测代替直接ListenAndServe,成功后http.Server.Serve(ln) - 占用判定:
errors.Is(err, syscall.EADDRINUSE),辅以错误串匹配兜底(Windows WSA 口径) - 地址解析需兼容
:8080、127.0.0.1:8080两种形态;host 部分保持不变只递增端口
验收标准
- 单测:占用某端口后开漂移能落到其他端口;关漂移时返回占用错误;
:0直通 - 单测:非占用错误(如权限)不做漂移
- 集成测试:模拟占用后启动服务,healthz 在漂移后的端口可访问
- 启动日志包含原端口、最终端口与尝试次数
- Dominant language
- Go
- Stars
- 2
- Forks
- 1
- Avg merge
- 1h 37m
- Merged PRs (30d)
- 6
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- No 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 LinuxSuRen/open-img-sync
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
LinuxSuRen/open-img-sync#18 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
LinuxSuRen/open-img-sync#19 ·
Maintainers usually reply within 1 day
-
容器化运行与多架构镜像发布(GHCR,同版本同源)Possibly taken @linuxsuren-fs claimed this 5 days ago. Openrequirement
Difficulty 4/5 3-5 days Newbie friendliness 25/100
LinuxSuRen/open-img-sync#8 · 1 comment ·
Maintainers usually reply within 1 day
-
单二进制分发与 CLI 规范(version 子命令、多平台 Release)Possibly taken @linuxsuren-fs claimed this 5 days ago. Openrequirement
Difficulty 4/5 3-5 days Newbie friendliness 35/100
LinuxSuRen/open-img-sync#7 · 1 comment ·
Maintainers usually reply within 1 day
-
Web 管理界面(Vue 3,嵌入单二进制)Possibly taken @linuxsuren-fs claimed this 5 days ago. Openrequirement
Difficulty 5/5 Over a week Newbie friendliness 20/100
LinuxSuRen/open-img-sync#6 · 1 comment ·
Maintainers usually reply within 1 day
All issues in LinuxSuRen/open-img-sync
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
aminueza/terraform-provider-minio#1406 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
kubernetes/kubeadm#3339 ·
-
A failed hydrate call can be dropped when the row's wait is ready tooPossibly taken @turbot-agent-fleet claimed this today. Openagent:ready
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
turbot/steampipe-plugin-sdk#1018 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
speakeasy-api/speakeasy#2159 ·
Maintainers usually reply within 1 day
-
enhancement needs-review
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day