Context with postgres

polaris · · 511 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<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 &#34;pq: canceling statement due to user request&#34;. And the more quantity of requests the more quantity of errors I get.</p> <p>But, if I don&#39;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

511 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传