2013-01-04 22 views
7

私はmongodbで予期せず閉鎖された接続について多くの検索を行ってきましたが、接続を閉じる必要がある人から質問を見つけることができます。node-mongodb-native MongoClientが予期せず接続を閉じる

私はnode-mongodb-nativeを使用してdbに接続していますが、一見ランダムな "Error:connection closed"というメッセージが表示され続けます。リクエストを手動で再試行すると(ブラウザの更新時に)リクエストが機能します。

何が原因で起こりますか?助ける簡単なオプションはありますか?

私が使用して私のデシベルのハンドルを取得しています:

 MongoClient.connect(connection_string, { auto_reconnect: true }, function (err, db) { 
    //server code/routes in here 
    } 

私はhttps://github.com/mongodb/node-mongodb-native/blob/master/lib/mongodb/connection/server.jsて探していたが、私は私をトリップされた接続プールは、一般的に管理されているかの私の限られた理解を実現します。私は彼らが私のサーバーの生涯にわたって開いたままになるという印象の下にいました。助けてもらえますか?

編集: mjhmのコメントを読んだ後、私はTCP keep aliveをより深く見ていきました。いくつかのサイトを横断して、これがAzureがやっているかもしれないと示唆しています(この質問は間違っています)。どうやら、Azureロードバランサは1分のアクティビティ後に接続を切断します。私はAzure Webサイトを利用しているため、適用される場合と適用されない場合がありますが、この洞察は新しい調査を開始するには十分に有望です。ここhttp://blogs.msdn.com/b/avkashchauhan/archive/2011/11/12/windows-azure-load-balancer-timeout-details.aspx

+0

あなたはより多くの情報を提供することはできますか?あなたのDBのローカルホストか別のマシンですか?接続がクローズされたメッセージをトリガーしているdbコールは何ですか?サーバー上の負荷はどれくらいですか? etc – mjhm

+0

こんにちは、dbはmongohqでホストされています。サービスにはほとんど負荷がありません。確実に問題を再現することはできませんが、find()呼び出しが失敗していることがわかります。私はnode-mongodb-nativeドライブでkeepAliveフラグをtrueにハードコーディングしようとしましたが、それはどちらも失敗しました。 –

+2

このメモにはいくつかの提案があります。http://christiankvalheim.com/post/32209721702/tcp-keepalive – mjhm

答えて

5

から詳細は:http://christiankvalheim.com/post/32209721702/tcp-keepalive

TCP keepalive One thing that comes up quite frequently as a question when using the mongodb node.js driver is a socket that stops responding. This usually have two sources.

There is a firewall in between the application and the mongodb instance and it does not observe keepAlive.

The socket timeout is to high on your system leaving the socket hanging and never closing. The first situation can be remedied by setting the socket connection options and enabling keepAlive and setting a hard timeout value on the socket. This will ensure that a correctly configured firewall will keep the connection alive and if it does not it will timeout. The other thing to tweak is the os tcp_keepalive_time. Basically it’s to high for something like MongoDB (default 2 hours on linux). Setting this lower will correctly timeout dead sockets and let the driver recover.

A good link to read more about it. http://www.mongodb.org/display/DOCS/Troubleshooting#Troubleshooting-Socketerrorsinshardedclustersandreplicasets

関連する問題