<p>In the beginning of my controller I create context with timeout like this</p>
<p>ctx, cancel := context.WithTimeout(context.Background(), time.Second * 10) defer cancel()</p>
<p>And then I use this context in each db request like this</p>
<p>QueryRowContext(ctx, query, ...args) // where ctx is context</p>
<p>However, when I load test my program I notice that some of my requests return error "pq: canceling statement due to user request". And the more quantity of requests the more quantity of errors I get.</p>
<p>But, if I don't use context with timeout, but rather use just context.Background(), I get no errors regardless of amount of requests.</p>
<p>Each request takes about 50ms, so timeout cannot occur. And I tried context with cancel context.WithCancel(context.Background()) and I also get these errors.</p>
<p>What may be a reason that these errors occur?</p>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
0 回复
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传