Last modified: 2014-08-19 18:18:19 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T70833, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 68833 - session management
session management
Status: RESOLVED FIXED
Product: Analytics
Classification: Unclassified
Wikimetrics (Other open bugs)
unspecified
All All
: Highest normal
: ---
Assigned To: Nobody - You can work on this!
u=AnalyticsEng c=Wikimetrics p=21 s=2...
:
Depends on:
Blocks: 69252
  Show dependency treegraph
 
Reported: 2014-07-30 01:07 UTC by Dan Andreescu
Modified: 2014-08-19 18:18 UTC (History)
7 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Dan Andreescu 2014-07-30 01:07:38 UTC
There MUST be a session not being closed somewhere, as while doing a lot of testing on wikimetrics, I encountered:

OperationalError: (OperationalError) (1203, "User u2543 already has more than 'max_user_connections' active connections") None None

This could happen if many parallel queries were open at the same time, but I don't think the setup I was using would cause that scenario.  So, we've tried to fix this a few times in the past, I think it's time we do it properly with flask-sqlalchemy or something else that is rock solid.  Basically after a refactor, we should never see manual calls to open sessions, they should all be using something like:

with session_thing:
    blah
Comment 1 Dan Andreescu 2014-07-30 15:56:54 UTC
looking through the labsdb databases, here's a list of the wikis to which connections were zombied while running RollingActiveEditor:

svwiki
ruwiki
lgwiki
nostalgiawiki
lijwiki
vowiktionary
swwiki
glwikibooks
htwiki
rnwiki
nawikibooks
Comment 2 nuria 2014-08-05 08:18:58 UTC
It is funny that this list is not much bigger if we were running queries for all projects (if that is not the case please disregard that comment).. could it be that open sessions are resulting due to timeouts when connecting to the db?
Comment 3 nuria 2014-08-06 16:37:36 UTC
Note that flask-sqlalchemy will help us with sessions instantiated by a web request. But not with sessions instantiated by the queue which does not interact with flask.

I think that tasks that access the db that throw out an exception while executing will in some cases leave a 'shadow' session. Most likely we need to wrap the task execution method for all tasks that celery executes and do the session handling there to make sure that 1) there is only one session used per task 2)we catch all exceptions and close that session. We will define the session scope and the task scope as being the same, just like flask-sqlalchemy equals the session scope and request scope.

This is a refactor that should be not too hard.
Comment 4 nuria 2014-08-06 16:41:10 UTC
Actually celery has worker signals: http://celery.readthedocs.org/en/latest/userguide/signals.html#worker-signals

I think we can tie to those to initiate and destroy sessions as those signals are tied to worker lifecycle.
Comment 5 Kevin Leduc 2014-08-07 19:36:54 UTC
Collaborative tasking on etherpad:
http://etherpad.wikimedia.org/p/analytics-68833
Comment 6 nuria 2014-08-07 19:50:48 UTC
Actually, not worker signals but rather task-signals: http://celery.readthedocs.org/en/latest/userguide/signals.html#task-signals

I will have some tests ready before tasking tomorrow
Comment 7 nuria 2014-08-08 11:20:35 UTC
see sample patch: https://gerrit.wikimedia.org/r/#/c/152888/
Comment 8 Gerrit Notification Bot 2014-08-12 15:22:14 UTC
Change 153616 had a related patch set uploaded by Milimetric:
Ensure wikimetrics session is always closed

https://gerrit.wikimedia.org/r/153616
Comment 9 Gerrit Notification Bot 2014-08-18 16:49:30 UTC
Change 154851 had a related patch set uploaded by Milimetric:
Disable pooling for mediawiki dbs

https://gerrit.wikimedia.org/r/154851
Comment 10 Gerrit Notification Bot 2014-08-19 16:34:02 UTC
Change 153616 merged by jenkins-bot:
Ensure database sessions are always cleaned up

https://gerrit.wikimedia.org/r/153616
Comment 11 Gerrit Notification Bot 2014-08-19 18:18:19 UTC
Change 154851 merged by Nuria:
Disable pooling for mediawiki dbs

https://gerrit.wikimedia.org/r/154851

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links