dthy81285 2015-04-13 14:13
浏览 37
已采纳

多个会话后mgo连接泄漏。

I'm writing a REST API in Go using MongoDB as a database and mgo as a driver. For the router, I'm using a custome one: pi.

At the program start up, I create a master mgo.Session and then, for each request handled, I copy the master session and closes it when I'm done.

But, when multiple requests are handled concurrently, I observe that MongoDB connection are still open even though I closed every mgo.Session copied.

Here is a sample of the output of lsof command:

milano-ru 18790 neel_v  118u  IPv4 34115804      0t0     TCP localhost:44238->localhost:27017 (ESTABLISHED)
milano-ru 18790 neel_v  119u  IPv4 34115812      0t0     TCP localhost:44241->localhost:27017 (ESTABLISHED)
milano-ru 18790 neel_v  120u  IPv4 34115813      0t0     TCP localhost:44242->localhost:27017 (ESTABLISHED)
milano-ru 18790 neel_v  121u  IPv4 34115814      0t0     TCP localhost:44243->localhost:27017 (ESTABLISHED)
milano-ru 18790 neel_v  122u  IPv4 34115815      0t0     TCP localhost:44244->localhost:27017 (ESTABLISHED)

So, after a couple of hours my application is running, it stops working since it cannot opens another MongoDB connection because a limit is reached (1024).

I've read about increasing ulimit of MongoDB, but is it really a solution?

  • 写回答

1条回答 默认 最新

  • dongying7847 2015-04-13 15:06
    关注

    I'm kind of upset and relieved at the same time, but I found my answer right after I posted my question...

    After checking on the mgo sessions, I can see that Dial set, by default a maxPoolSize of 4096... After trying to reduce the pool size it solved my problem.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 STM32 INMP441无法读取数据
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境