duanbi5906 2018-08-07 12:17
浏览 64

通过Docker SSH隧道进入lang服务和PostgreSQL

I have got a resources release problem.

  1. PostgreSQL runs on a server 1.
  2. Go lang service runs on a server 2 in a Docker container.
  3. There is an ssh tunnel Docker container for a connection between the database and the service. It does not know anything except ssh.

Docker is in swarm mode.

The service (2) connects to the database via golang database/sql library. I call sql.Open(), driverName = "postgres". Then everything is ok. In some time, may be in 30 minutes, (*DB) Query() returns an error read: connection reset by peer. If I call (*DB) Ping() previously, Ping() does not return an error, but the next call Query() does.

If I call Query() again in some time, a new connection is created. I can see it in a select * from pg_stat_activity; query in the database (state = idle). But the previous connection has not been removed.

So I call (*DB) Close(), create a new DB object and call sql.Open().

Close closes the database, releasing any open resources.

(https://golang.org/pkg/database/sql/#Conn.Close)

But after the Close call I can still see the connection in a select * from pg_stat_activity; query in the database (state = idle). I see the bad connection and the new one.

As the result there is a resources leak.

What is the correct way to handle a read: connection reset by peer error? Why have I got this error?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
    • ¥15 lammps拉伸应力应变曲线分析
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
    • ¥30 python代码,帮调试,帮帮忙吧
    • ¥15 #MATLAB仿真#车辆换道路径规划
    • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建