fix(remote): preserve caller info for default server decode errors#1967
Draft
ChocoLZS wants to merge 4 commits into
Draft
fix(remote): preserve caller info for default server decode errors#1967ChocoLZS wants to merge 4 commits into
ChocoLZS wants to merge 4 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests.
Additional details and impacted files@@ Coverage Diff @@
## main #1967 +/- ##
===========================================
- Coverage 62.84% 51.87% -10.98%
===========================================
Files 394 332 -62
Lines 30267 23337 -6930
===========================================
- Hits 19022 12105 -6917
+ Misses 9948 9905 -43
- Partials 1297 1327 +30
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
fix
Check the PR title.
(Optional) Translate the PR title into Chinese.
修复默认服务端 decode 错误日志中调用方信息丢失的问题
(Optional) More detailed description for this PR(en: English/zh: Chinese).
en:
This is a more complete fix based on PR #1272 for the logging issue reported in #1267.
The issue is limited to the default server handler path, which is reused by gonet, netpoll, and invoke. Before PR #1272, decode/read errors were logged inside
OnRead, so request rpcinfo was still available. PR #1272 moved the final log to the outer fallbackOnErrorto avoid duplicate error logs, but that fallback runs too late for request rpcinfo:OnReadresets the reused rpcinfo in deferred cleanup before the outer fallback log.OnReadcreates a request ctx/rpcinfo, but only returns an error. The outer fallback still uses the connection ctx returned byOnActive.This PR restores the correct logging timing by logging decode/read errors inside
OnRead, while request rpcinfo is still available. It also keeps PR #1272's duplicate-log optimization by returning an unwrap-compatible marker:The returned error remains non-nil, so the outer trans server still closes the connection as before.
Unwrappreserveserrors.Is/As, and the marker only suppresses the second fallback log.Checked other
ServerTransHandlerimplementations: netpollmux already logs read/write errors before rpcinfo reset; nphttp2 and ttstream use separate stream handling flows; detection only delegates to the selected handler. Business handler panics are also unaffected because they are recovered and logged insideOnReadbefore deferred cleanup.A regression test is added for both rpcinfo pool modes to verify that read errors are logged with
remoteServiceand that the outer fallback log is skipped.zh(optional):
这是基于 PR #1272 的更完整修复,用于解决 #1267 中报告的日志问题。
该问题仅限于默认服务端 handler 路径,也就是 gonet、netpoll、invoke 复用的路径。PR #1272 之前,decode/read 错误是在
OnRead内部打印的,因此还能拿到请求级 rpcinfo。PR #1272 为了解决重复错误日志问题,把最终日志交给外层兜底OnError打印,但兜底打印对请求级 rpcinfo 来说太晚了:OnRead的 deferred cleanup 会在外层兜底打印前 reset 复用的 rpcinfo。OnRead会创建 request ctx/rpcinfo,但只返回 error;外层兜底仍然使用OnActive返回的 connection ctx。本 PR 恢复正确的打印时机:在
OnRead内部、请求级 rpcinfo 仍然可用时打印 decode/read 错误。同时保留 PR #1272 的去重效果:返回一个支持Unwrap的 marker error,用来标记该错误已经打印过:返回错误仍然非 nil,外层 trans server 仍会按原逻辑关闭连接;
Unwrap保留errors.Is/As行为;marker 只用于跳过第二条兜底日志。已检查其他
ServerTransHandler实现:netpollmux 已经在 rpcinfo reset 前打印 read/write 错误;nphttp2 和 ttstream 使用独立的 stream 处理流程;detection 只负责转发到选中的 handler。业务 handler panic 也不受影响,因为 panic 会在OnRead内部、deferred cleanup 前被 recover 并打印。新增回归测试,覆盖 rpcinfo pool 开启和关闭两种模式,验证 read error 日志包含
remoteService,且外层兜底日志会被跳过。(Optional) Which issue(s) this PR fixes:
Fixes #1267
(optional) The PR that updates user documentation: