2013-01-04 14 views
7

मैं मोंगोडब में अप्रत्याशित रूप से बंद कनेक्शन के लिए बहुत कुछ खोज रहा हूं लेकिन केवल उन लोगों से प्रश्न ढूंढ सकता हूं जो उनके कनेक्शन बंद करना चाहते हैं।नोड-मोंगोडब-मूल मोंगो क्लाइंट अप्रत्याशित रूप से बंद कनेक्शन

मैं एक डीबी से कनेक्ट करने के लिए नोड-मगोडब-मूल का उपयोग कर रहा हूं, लेकिन मुझे लगता है कि "त्रुटि: कनेक्शन बंद" संदेश प्रतीत होता है। अगर मैं मैन्युअल रूप से अनुरोध (ब्राउजर रीफ्रेश) का अनुरोध करता हूं तो अनुरोध काम करता है।

कोई विचार यह क्या कारण है? क्या कोई आसान विकल्प है जो मदद करेगा?

मैं अपने db हैंडल का उपयोग हो रही है:

 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 की टिप्पणियों को पढ़ने के बाद, मैंने टीसीपी को ज़िंदा रखने में और गहराई से देखना शुरू कर दिया। कुछ साइटों पर ठोकरें जो सुझाव देते हैं कि यह Azure का कर सकता है (और यह सवाल अब गलत वर्गीकृत है!)। जाहिर है, Azure लोड बैलेंसर गतिविधि के 1 मिनट के बाद कनेक्शन मारता है। मैं Azure वेबसाइट्स का उपयोग कर रहा हूं, इसलिए यह लागू हो सकता है या नहीं भी हो सकता है, लेकिन मुझे लगता है कि यह अंतर्दृष्टि जांच की एक नई पंक्ति शुरू करने के लिए पर्याप्त वादा कर रही है। अधिक जानकारी यहां http://blogs.msdn.com/b/avkashchauhan/archive/2011/11/12/windows-azure-load-balancer-timeout-details.aspx

+0

आप अधिक जानकारी दे सकते हैं? क्या आपका डीबी लोकहोस्ट या कोई अन्य मशीन है? कनेक्शन बंद संदेशों को ट्रिगर करने वाले डीबी कॉल क्या हैं? सर्वर पर कितना भार है? आदि – mjhm

+0

हाय, डीबी mongohq पर होस्ट किया गया है। सेवा पर बहुत कम भार है। मैं इस मुद्दे को विश्वसनीय रूप से पुन: पेश नहीं कर सकता, लेकिन मुझे लगता है कि खोज() कॉल निश्चित रूप से विफल हो रही हैं। मैंने नोड-मोंगोड-मूल ड्राइव में सत्य को जीवंत ध्वज को सही करने की कोशिश की, लेकिन यह भी काम नहीं करता था। –

+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