Skip to content
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

Panic after upgrade v3.34.0 to v3.37.1 #248

Closed
YiuTerran opened this issue Jun 27, 2023 · 5 comments
Closed

Panic after upgrade v3.34.0 to v3.37.1 #248

YiuTerran opened this issue Jun 27, 2023 · 5 comments

Comments

@YiuTerran
Copy link

没有太多时间定位,直接回滚了。问题应该是:

github.com/imroc/req/v3.RoundTripFunc.RoundTrip(0x20?, 0x14bc700?)
C:/Users/taira/go/pkg/mod/github.com/imroc/req/v3@v3.37.1/client.go:1457 +0x1f
导致

@imroc
Copy link
Owner

imroc commented Jun 27, 2023

能给多一点信息吗?用法和完整堆栈

@YiuTerran
Copy link
Author

堆栈很长,大部分是业务相关的,稍微完整一点的如下:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x542960]

goroutine 419 [running]:
net/url.(*URL).String(0x0)
        C:/Program Files/Go/src/net/url/url.go:810 +0x40
gitlab.cscec3b-iti.com/SmartInfrastructure/go-common/apm.SetReqClientTracer.func1.1(0xc00004c200)
        C:/Users/taira/go/pkg/mod/gitlab.cscec3b-iti.com/!smart!infrastructure/go-common/apm@v1.0.1/http.go:38 +0x21b
github.com/imroc/req/v3.RoundTripFunc.RoundTrip(0x20?, 0x14bc700?)
        C:/Users/taira/go/pkg/mod/github.com/imroc/req/v3@v3.37.1/client.go:1457 +0x1f
github.com/imroc/req/v3.(*Request).do(0xc00004c200)
        C:/Users/taira/go/pkg/mod/github.com/imroc/req/v3@v3.37.1/request.go:591 +0xbf
github.com/imroc/req/v3.(*Request).Do(0xc00004c200, {0xc0058eb440?, 0x13ec2c0?, 0x18ac190?})
        C:/Users/taira/go/pkg/mod/github.com/imroc/req/v3@v3.37.1/request.go:575 +0x17f
gitlab.cscec3b-iti.com/SmartInfrastructure/go-common/gb28181/hermes.(*Client).getToken(0xc000598050, {0x18bc2c8, 0xc00020a000})
        C:/Users/taira/go/pkg/mod/gitlab.cscec3b-iti.com/!smart!infrastructure/go-common/gb28181@v1.3.1/hermes/http.go:44 +0x258
gitlab.cscec3b-iti.com/SmartInfrastructure/go-common/gb28181/hermes.Query[...].func1(0x1?)
        C:/Users/taira/go/pkg/mod/gitlab.cscec3b-iti.com/!smart!infrastructure/go-common/gb28181@v1.3.1/hermes/http.go:80 +0x2e
github.com/samber/lo.AttemptWithDelay(0x3, 0x417653?, 0xc0058eb5f8)
        C:/Users/taira/go/pkg/mod/github.com/samber/lo@v1.38.1/retry.go:171 +0x97
gitlab.cscec3b-iti.com/SmartInfrastructure/go-common/gb28181/hermes.Query[...]({0x18bc2c8, 0xc00020a000}, 0xc000598050, {0x16aca0d, 0x1f}, 0xc0005302c0, {0x0, 0x0, 0x0})

@imroc
Copy link
Owner

imroc commented Jun 27, 2023

看起来是用了client中间件,具体怎么用的?能否构造跟业务无关的可复现代码贴出来?

@YiuTerran
Copy link
Author

我看了一下代码,应该是req.URL之前不是nil,现在变成nil了。是不是改成RawURL就行了?

// SetReqClientTracer 为req的http客户端添加tracer
func SetReqClientTracer(c *req.Client, tracer trace.Tracer) {
	c.WrapRoundTripFunc(func(rt req.RoundTripper) req.RoundTripFunc {
		return func(req *req.Request) (resp *req.Response, err error) {
			ctx := req.Context()
			apiName, ok := ctx.Value(ApiNameKey).(string)
			if !ok {
				apiName = req.URL.Path
			}
			_, span := tracer.Start(req.Context(), apiName)
			defer span.End()
			span.SetAttributes(
				attribute.String("http.url", req.URL.String()),
				attribute.String("http.method", req.Method),
				attribute.String("http.req.header", req.HeaderToString()),
			)
			//如果body不太大的话,记录下来
			if len(req.Body) > 0 && len(req.Body) < 10240 {
				span.SetAttributes(
					attribute.String("http.req.body", string(req.Body)),
				)
			}
			tc.Inject(ctx, propagation.HeaderCarrier(req.Headers))
			resp, err = rt.RoundTrip(req)
			if err != nil {
				span.RecordError(err)
				span.SetStatus(codes.Error, err.Error())
			}
			if resp.Response != nil {
				span.SetAttributes(
					attribute.Int("http.status_code", resp.StatusCode),
					attribute.String("http.resp.header", resp.HeaderToString()),
					attribute.String("http.resp.body", resp.String()),
				)
			}
			return
		}
	})
}

@imroc imroc closed this as completed in d9fef28 Jun 28, 2023
@imroc
Copy link
Owner

imroc commented Jun 28, 2023

确实是新版引入的,已修复

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants