-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
session access has a certain probability of not getting the value #2772
Comments
@gqcn 这个问题解决吗? |
@gqcn Is this problem solved? |
@famiou It seems that there is a problem with the test code you wrote. The /get interface is written recursively, and the for is still an infinite loop. System resources will eventually be exhausted, causing g.Client().GetContent in the code to request /get to fail , so if you can’t get the result, you’re at your panic code. I haven't actually tested it, just speculated from the code, it's just for reference~ |
这个应该不是资源耗尽,我项目中的请求没有这么频繁也会出现这种情况,偶尔有个接口就是获取不到值,这是我单独拿出来的一个请求示例代码,刚开始获取没有问题,但后面请求报错多了就会出现
|
你的/get接口代码: group.GET("/get", func(r *ghttp.Request) {
for i := 0; i < 10; i++ {
ctx := context.Background()
go func() {
for {
res := g.Client().GetContent(ctx, "http://127.0.0.1:8005/get")
j := gjson.New(res)
if j.Get("abc").IsEmpty() {
panic("abc error")
}
g.Log().Info(ctx, "res===", res)
}
}()
}
r.Session.SetId("test")
r.Response.WriteJson(g.Map{
"abc": r.Session.MustGet("abc"),
})
}) 是否去掉了下面这段? for i := 0; i < 10; i++ {
ctx := context.Background()
go func() {
for {
res := g.Client().GetContent(ctx, "http://127.0.0.1:8005/get")
j := gjson.New(res)
if j.Get("abc").IsEmpty() {
panic("abc error")
}
g.Log().Info(ctx, "res===", res)
}
}()
} |
@windvalley 去掉了 |
@windvalley removed |
@famiou 如果去掉了, 我测是没问题的, 跑了5分钟了也没出错. 建议你把 res, err := g.Client().Get(ctx, "http://127.0.0.1:8005/get")
if err != nil {
g.Log().Errorf(ctx, "res: %+v, error: %v", res, err)
continue
} 看看究竟报的什么错误 |
If @famiou is removed, I tested that there is no problem, and there is no error after running for 5 minutes. It is recommended that you change the line res, err := g.Client().Get(ctx, "http://127.0.0.1:8005/get")
if err != nil {
g.Log().Errorf(ctx, "res: %+v, error: %v", res, err)
continue
} See what error is reported |
@windvalley 报错如下
|
@famiou 看报错很明显了, 这是客户端socket错误, 和服务端没啥关系, 具体可以google一下 |
@famiou It is obvious that the error is reported. This is a client socket error and has nothing to do with the server. You can google it for details |
@windvalley 我找到我获取不到session的原因了,在一次请求中,如果我去更新session,然后再下次请求有可能获取不到session的数据
|
@famiou 你好,我没有复现这个问题。请使用最新版本再试试,如果问题依旧请将最小可复现的完整代码,提交新的 |
@famiou Hello, I have not reproduced this problem. Please use the latest version and try again. If the problem persists, please submit the smallest reproducible complete code to |
1. What version of
Go
and system type/arch are you using?go version go1.20.2 windows/amd64
2. What version of
GoFrame
are you using?require github.com/gogf/gf/v2 v2.3.1
3. Can this issue be re-produced with the latest release?
yes
4. What did you do?
5. What did you expect to see?
首先运行
gf run main.go
让程序跑起来http://127.0.0.1:8005/set 浏览器打开链接,设置session
然后运行http://127.0.0.1:8005/get ,后台跑程序,取不到值的时候会报错
获取session的时候有一定机率获取不到值
6. What did you see instead?
应该是每一次都能看到值
The text was updated successfully, but these errors were encountered: