Closed mhkeller closed 9 years ago
putting this on hold for now. low priority.
reopening because it is coming up in sous chefs running as well as running make update
if you run top
there are about four dozen postgresql processes still hanging around. there must be somewhere that isn't closing these connections.
adding this to make update
helps but is not a real solution
sudo service postgresql restart
Will leave open until further testing, but I'm fairly certain this commit will fix the issue. In the traceback you can see the error is occurring here:
newslynx.exc.ConfigError: Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/newslynx/core.py", line 77, in <module>
db_session.execute('SET TIMEZONE TO UTC')
I had been using db_session
to make requests to the database outside of the context of the Flask app, since this is a limitation of Flask-SQLAlchemy. The problem is that this was being called every time a sous chef was loaded, since I check whether they have valid python paths and are installed by loading the modules. Since each sous chef uses underlying elements of newslynx-core
, every time a sous chef was loaded, so was newslynx-core
, and thus this session as well. The problem is that it was never being closes. Now I'll just generate these sessions using a function, and load them were I need them.
has this come up again @mhkeller ?
This has been okay
Le Sep 12, 2015 à 01:39, Brian Abelson notifications@github.com a écrit :
has this come up again @mhkeller ?
— Reply to this email directly or view it on GitHub.
Just got it loading article detail view
"Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request() File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e) File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb) File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request() File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args) File "/usr/local/lib/python2.7/dist-packages/newslynx/views/decorators.py", line 35, in decorated_function
return f(*args, **kw) File "/usr/local/lib/python2.7/dist-packages/newslynx/views/decorators.py", line 75, in decorated_function
return f(*args, **kw) File "/usr/local/lib/python2.7/dist-packages/newslynx/views/api/events_api.py", line 294, in search_events
for by, result in event_facet_pool.imap_unordered(fx, kw['facets']): File "/usr/local/lib/python2.7/dist-packages/gevent/pool.py", line 222, in next
raise value.excOperationalError: (psycopg2.OperationalError) FATAL: sorry, too many clients alreadyFATAL: sorry, too many clients already"
This error is still coming up frequently.
currently limit in postgresql conf is 100 fyi
Using the automation setup, to temporarily increase limit:
vagrant ssh
sudo -u postgres psql
SHOW config_file;
That will print the location of the postgres conf file
sudo vi <file>
Change the limit to 500. Logout with logout
and then make update
to restart.
This is going to require a more serious audit. Would be good to be able to sit down with you bc i don't have access to prod server. Hard to know exactly where the sessions are not getting closed without seeing the step-by-step process you're taking which generates them.
This issue seems relevant:
http://stackoverflow.com/questions/25768428/sqlalchemy-connection-errors
I'll need to go through my sql code and check if I'm sending multiple commands in a single call to db.session.execute
. I could also try not using gevent
with gunicorn
.
A handy postgresql command for checking idle postgres processes:
select * from pg_stat_activity where state = 'idle in transaction';
I should have cleaned up all of the session leaks. I'm also going to add a simple cronjob which kills idle postgres transactions:
$ ps aux | grep postgres | grep 'idle in transaction' | awk '{print $2}' | xargs kill -9
added script to automation which kills idle transactions older than 15 minutes every 10 minutes. https://github.com/newslynx/automation/commit/19ecbf09d801891fb46197f005e5ebbb2eea0a28
when updating core