Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix connection leaks: - Close connection before reassigning server re…
…ference - Fix how servers are iterated when closing
- Loading branch information
Showing
1 changed file
with
18 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f75f560
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any chance this could fix an issue with connections and no activity experiencing some weird issues? I have noticed that after 20 minutes of no activity on any of the connections will result in a future request waiting for ~60 seconds before a failed to connect error is thrown. After that error is thrown a new connection is automatically created and everything works fine again. mongodb logs don't show an end connection for anywhere between 37 and 170 minutes. If I create a really simple setInterval and make a request every 60 seconds I never experience this problem. Needless to say it is driving me nuts!
UPDATE: I should state that I'm using mongoose 3.1.2
f75f560
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will likely not fix that issue. you should try to set keepalive and timeout. are you also doing this through a firewall ? after 10 minutes of no activity mongod closes a connection. if the end signal is not reaching the driver it means something is consuming it between the db and the driver my guess some sort of firewall.
f75f560
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sberryman mongoose 3.1.2 is using 1.1.7 so maybe test again with this change and post your results back here.
f75f560
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh nvm
f75f560
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aheckmann what is the best way to set config params for the native connection? I'm passing them in as part of the connection string as the first arg for mongoose.connect. I see you have an issue created to provide better explication of connect and createConnection and am really looking forward to that being added to the documentation. I'm using mongoose.connect right now and again, passing the config params by doing something along these lines:
f75f560
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@christkv thanks for that 10 minute comment. I finally tracked down the article on http://www.mongodb.org/display/DOCS/Troubleshooting#Troubleshooting-Socketerrorsinshardedclustersandreplicasets which pointed me to tcp_keepalive_interval which was the default value of 7200 (7200000 on solaris) and changed the value to 5 minutes. BAM no more issues with MongoDB or Redis. I only wasted 4 days on this but glad it appears to be behind me.
f75f560
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sberryman I updated the api docs with some more examples for now: http://mongoosejs.com/docs/api.html#index_Mongoose-createConnection
in a nutshell, you pass an options object after the uri.