dongyikong6207 2019-01-11 18:02
浏览 712

docker中的数据库连接超时

Environment

  • Environment: Mac and Docker
  • Language: GoLang
  • Database: Postgresql

Expected Behavior

We have a connection pool used to connect to database. The time of database connection may vary from 1 minute up to 20 minutes depending on the functions being called.

Actual Behavior

  • Running in local: everything is fine.
  • Running in Docker: DB connection that is less than 5 minutes is fine. For DB connection that is longer than 5 minutes, every 5-6 minutes the connection is broken in docker and a new connection is initiated automatically. After 3 reconnections, following error is returned and process is terminated

    driver: bad connection

Some Tries

  • try to ping database during the function call to keep connection alive -- not works (working in some simple cases, but not in complicate case and not stable.
  • try to ping database during function call with same connection using db.SetMaxOpenConns(1) and db.SetMaxIdleConns(1) -- not works.
  • try to set connection life to longer with db.SetConnMaxLifetime() -- not works.

Some Info

After some search, the possible reason is that docker periodically checks connections and time them out if connection is alive for 300 seconds and no response returns. Not find any way to overwrite this configuration.

https://github.com/moby/moby/issues/36053

https://github.com/docker/for-mac/issues/2442

How can I get around this issue? Appreciate if any help.

  • 写回答

0条回答

    报告相同问题?

    问题事件

    • 提问应符合社区要求 5月22日

    悬赏问题

    • ¥15 stata安慰剂检验作图但是真实值不出现在图上
    • ¥15 c程序不知道为什么得不到结果
    • ¥40 复杂的限制性的商函数处理
    • ¥15 程序不包含适用于入口点的静态Main方法
    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题