req icon indicating copy to clipboard operation
req copied to clipboard

出现fatal error: concurrent map read and map write。

Open wuchuwei opened this issue 1 year ago • 3 comments

goroutine 5677 [running]: github.com/imroc/req/v3.parseRequestHeader(0xc000626dc0, 0xc000a44000) /root/go/pkg/mod/github.com/imroc/req/[email protected]/middleware.go:537 +0x391 github.com/imroc/req/v3.(*Request).do(0xc000a44000) /root/go/pkg/mod/github.com/imroc/req/[email protected]/request.go:660 +0xac7 github.com/imroc/req/v3.(*Request).Do(0xc000a44000, {0x0, 0x0, 0xc000e067b0?}) /root/go/pkg/mod/github.com/imroc/req/[email protected]/request.go:636 +0x38f github.com/imroc/req/v3.(*Request).Send(0xc000a44000, {0xec2aad, 0x3}, {0xc000042540, 0x3c}) /root/go/pkg/mod/github.com/imroc/req/[email protected]/request.go:726 +0xfb github.com/imroc/req/v3.(*Request).Get(...) /root/go/pkg/mod/github.com/imroc/req/[email protected]/request.go:745 main.(*config).request.func4({0xc000042540, 0x3c}, 0x3, 0xc000590200) /opt/go-project/net_check/test2.go:529 +0x185 created by main.(*config).request in goroutine 5653 /opt/go-project/net_check/test2.go:527 +0x1265 请问这个问题要如何处理?

wuchuwei avatar Nov 04 '24 13:11 wuchuwei

问题出现在client设置User-agent上。

wuchuwei avatar Nov 05 '24 01:11 wuchuwei

问题出现在client设置User-agent上。

正在处理请求的过程中设置 User-Agent? 这种应该可能有问题,一般都在用client前先设置好User-Agent,req本身没有加锁,默认加锁影响性能,如果实在要这么用(请求过程中改client User-Agent),可以自己在外围加锁控制下

imroc avatar Nov 05 '24 02:11 imroc

问题出现在client设置User-agent上。

正在处理请求的过程中设置 User-Agent? 这种应该可能有问题,一般都在用client前先设置好User-Agent,req本身没有加锁,默认加锁影响性能,如果实在要这么用(请求过程中改client User-Agent),可以自己在外围加锁控制下

意思是这样吗?用req.SetUserAgent(xxx) 不要用req.C().SetUserAgent(xxx)

wuchuwei avatar Nov 13 '24 10:11 wuchuwei