-
Notifications
You must be signed in to change notification settings - Fork 41
fix: rename instance error when only perform name modify #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
修复了在更新隧道时,由于 URL 参数顺序不同导致的误判问题。 **问题描述:** 当编辑隧道配置时,即使参数内容相同但顺序不同(如 `log=info&mode=2&tls=1` vs `log=info&tls=1&mode=2`),系统会错误地认为配置发生了变化,导致触发不必要的实例更新操作。 **解决方案:** - 新增 `normalizeCommandLine` 函数,将 URL 查询参数按字母顺序排序后再进行比较 - 在比较新旧 commandLine 之前,先对两者进行规范化处理 - 添加了错误处理,如果规范化失败会回退到原始字符串比较 - 改进了日志输出,将配置变化的日志从 Error 级别改为 Info 级别 **影响范围:** - 仅影响隧道编辑功能的判断逻辑 - 确保参数顺序不影响配置比较结果 - 避免不必要的隧道实例更新操作 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Purpose: Prevent erroneous 409 conflicts when updating a tunnel name without changing its parameters by distinguishing pure name changes from real instance configuration updates through normalized commandLine comparison.
- Add normalizeCommandLine to order query parameters deterministically before comparison
- Introduce conditional path to call RenameInstance instead of UpdateInstance when only the name changed
- Adjust logging levels and add fallback logic when normalization fails
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
internal/api/tunnel.go
Outdated
| // 获取所有的参数键并排序 | ||
| keys := make([]string, 0, len(values)) | ||
| for k := range values { | ||
| keys = append(keys, k) | ||
| } | ||
| sort.Strings(keys) | ||
|
|
||
| // 按排序后的顺序重建查询参数 | ||
| params := make([]string, 0, len(keys)) | ||
| for _, k := range keys { | ||
| for _, v := range values[k] { | ||
| params = append(params, fmt.Sprintf("%s=%s", k, v)) | ||
| } | ||
| } | ||
|
|
||
| // 重建完整的 commandLine | ||
| if len(params) > 0 { | ||
| return base + "?" + strings.Join(params, "&"), nil | ||
| } |
Copilot
AI
Oct 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Manual reconstruction of the query string does not perform URL encoding and can change semantics (e.g., spaces, &, =, +, % in keys/values) compared to the original; it may also introduce a trailing = for naked keys, leading to false inequality or broken commands. Use values.Encode() (which sorts keys and applies proper escaping) or apply url.QueryEscape to both key and value: params = append(params, fmt.Sprintf("%s=%s", url.QueryEscape(k), url.QueryEscape(v))). Example replacement: return base + "?" + values.Encode(), nil.
| // 获取所有的参数键并排序 | |
| keys := make([]string, 0, len(values)) | |
| for k := range values { | |
| keys = append(keys, k) | |
| } | |
| sort.Strings(keys) | |
| // 按排序后的顺序重建查询参数 | |
| params := make([]string, 0, len(keys)) | |
| for _, k := range keys { | |
| for _, v := range values[k] { | |
| params = append(params, fmt.Sprintf("%s=%s", k, v)) | |
| } | |
| } | |
| // 重建完整的 commandLine | |
| if len(params) > 0 { | |
| return base + "?" + strings.Join(params, "&"), nil | |
| } | |
| // 使用标准库方法对参数排序并进行URL编码 | |
| encoded := values.Encode() | |
| if encoded != "" { | |
| return base + "?" + encoded, nil | |
| } |
优化了 normalizeCommandLine 函数,通过使用 Encode() 方法重建查询参数,自动处理参数排序和编码,简化了代码逻辑。此更改确保了在比较 URL 参数时的准确性和一致性,进一步提升了隧道编辑功能的稳定性。
|
@yosebyte 已经根据建议修复,请review |
修复了新版API在更新隧道时,由于仅更新隧道名字导致的409错误
问题描述:
当编辑隧道配置时,如果仅更新隧道名字,当走到updateInstance的函数中时,CORE会返回409错误导致名字更新失败
解决方案:
normalizeCommandLine函数,将 URL 查询参数按字母顺序排序后再进行比较影响范围: