go iris web 框架,同时有两个请求到达go的时候,参数会有上次请求的部分参数。最后导致json序列化时失败
readObjectStart: expect { or n, but found , error found in #0 byte of ...||..., bigger context ...||...
场景重现:
1、登录
在go语言的net/http/server.go
源码 1822行func (c *conn) serve(ctx context.Context) {}
函数debug,
c.bufr.buf
的值是:
POST /auth/login HTTP/1.1
Host: localhost:9000
Connection: keep-alive
Content-Length: 405
Accept: application/json, text/plain, */*
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36
Content-Type: application/json;charset=UTF-8
Sec-Fetch-Site: same-site
Sec-Fetch-Mode: cors
Sec-Fetch-Dest: empty
Referer: http://localhost:8080/auth
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9
{"a1":"zmKK5HMForFJiasoLrzbWfIudvCxgKeWooRtJdpBNmc6ywy93VSJOLTtHWond3Y2QUamqylOOQ5kKlgytXDjV29b1J82UAsZs3Me0upq4mHJrmcGyqPsjMKrLe5ESbP7ex2/yumZyYjA184NCeBtegQ6FRuOtWtsnLvPrxeVhek=","a2":"ZsCPD7Oq4r50jKIRX9Zr8y64P5DJpxLw0MOM43UjhiFPCB4FvWCUYO76kdrxJKMhOXyHKlChxoR/5iIn+YhxtB8eYKvE7qtKFVmyu6mZ7uKm4svehRTLBaCQBKxJ9H9bICwQncpW7B9mvvJyQKBXX17/yWTDT61xwxPSsGUSNXw=","a3":"c9f45a8b-9b54-44bb-81be-a6af87b1c28f"}
这里的参数获取是OK的,登录也是成功的。
2,登录后同时发起了2个请求reload
和page
,其中reload
请求不带参数,page
携带参数:
但是在net/http/server.go
源码 1822行func (c *conn) serve(ctx context.Context) {}
函数断点是发现参数异常:
POST /subject/page HTTP/1.1
Host: localhost:9000
Connection: keep-alive
Content-Length: 21
Accept: application/json, text/plain, */*
Authorization: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJ1c2VyIiwiZXhwIjoxNTg5MDg4NTM2LCJqdGkiOiIxMjM1ODA2ODIyNDM1MTMxMzkyIiwiaWF0IjoxNTg5MDg3NjM2LCJpc3MiOiJxeHVuIiwibmJmIjoxNTg5MDg2NzM2LCJzdWIiOiJ1c2VyLXByb2ZpbGUifQ.sy1wg-C1vNkTT_R5dpjUZPUqY_YBmZ4ICbR0gCEvM8w
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36
Content-Type: application/json;charset=UTF-8
Sec-Fetch-Site: same-site
Sec-Fetch-Mode: cors
Sec-Fetch-Dest: empty
Referer: http://localhost:8080/home/subject
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9
{"limit":10,"page":1}ehRTLBaCQBKxJ9H9bICwQncpW7B9mvvJyQKBXX17/yWTDT61xwxPSsGUSNXw=","a3":"c9f45a8b-9b54-44bb-81be-a6af87b1c28f"}
其中的参数竟然有部分以前的请求参数混入其中。导致json序列化失败,请问下这个问题怎么解决,原因是什么?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…