Skip to content

workaround db connection getting closed at runtime...#307

Merged
rspeer merged 1 commit intocommonsense:masterfrom
amirouche:master
Sep 7, 2021
Merged

workaround db connection getting closed at runtime...#307
rspeer merged 1 commit intocommonsense:masterfrom
amirouche:master

Conversation

@amirouche
Copy link

@amirouche amirouche commented Aug 19, 2021

... for unknown reasons, the db connection is closed at runtime, due
to a high load. Here is an example traceback:

 [2021-08-15 17:00:46,840] ERROR in app: Exception on /a/[/r/EtymologicallyRelatedTo/,/c/en/drag/,/c/nds/dragge/] [GET]
 Traceback (most recent call last):
   File "/home/conceptnet/env/lib/python3.6/site-packages/flask/app.py", line 2447, in wsgi_app
     response = self.full_dispatch_request()
   File "/home/conceptnet/env/lib/python3.6/site-packages/flask/app.py", line 1952, in full_dispatch_request
     rv = self.handle_user_exception(e)
   File "/home/conceptnet/env/lib/python3.6/site-packages/flask/app.py", line 1821, in handle_user_exception
     reraise(exc_type, exc_value, tb)
   File "/home/conceptnet/env/lib/python3.6/site-packages/flask/_compat.py", line 39, in reraise
     raise value
   File "/home/conceptnet/env/lib/python3.6/site-packages/flask/app.py", line 1950, in full_dispatch_request
     rv = self.dispatch_request()
   File "/home/conceptnet/env/lib/python3.6/site-packages/flask/app.py", line 1936, in dispatch_request
     return self.view_functions[rule.endpoint](**req.view_args)
   File "/home/conceptnet/conceptnet5/web/conceptnet_web/web.py", line 133, in browse_node
     results = responses.lookup_paginated(path, offset=offset, limit=limit)
   File "/home/conceptnet/conceptnet5/conceptnet5/api.py", line 150, in lookup_paginated
     found = FINDER.lookup(term, limit=(limit + 1), offset=offset)
   File "/home/conceptnet/conceptnet5/conceptnet5/db/query.py", line 142, in lookup
     return self.lookup_assertion(uri)
   File "/home/conceptnet/conceptnet5/conceptnet5/db/query.py", line 194, in lookup_assertion
     cursor = self.connection.cursor()
 psycopg2.InterfaceError: connection already closed

This patch will re-create the connection any time the connection is
closed. Bonus: factor connection creation inside a property called
connection.

ref: #306

... for unknown reasons, the db connection is closed at runtime, due
to a high load. Here is an example traceback:

 [2021-08-15 17:00:46,840] ERROR in app: Exception on /a/[/r/EtymologicallyRelatedTo/,/c/en/drag/,/c/nds/dragge/] [GET]
 Traceback (most recent call last):
   File "/home/conceptnet/env/lib/python3.6/site-packages/flask/app.py", line 2447, in wsgi_app
     response = self.full_dispatch_request()
   File "/home/conceptnet/env/lib/python3.6/site-packages/flask/app.py", line 1952, in full_dispatch_request
     rv = self.handle_user_exception(e)
   File "/home/conceptnet/env/lib/python3.6/site-packages/flask/app.py", line 1821, in handle_user_exception
     reraise(exc_type, exc_value, tb)
   File "/home/conceptnet/env/lib/python3.6/site-packages/flask/_compat.py", line 39, in reraise
     raise value
   File "/home/conceptnet/env/lib/python3.6/site-packages/flask/app.py", line 1950, in full_dispatch_request
     rv = self.dispatch_request()
   File "/home/conceptnet/env/lib/python3.6/site-packages/flask/app.py", line 1936, in dispatch_request
     return self.view_functions[rule.endpoint](**req.view_args)
   File "/home/conceptnet/conceptnet5/web/conceptnet_web/web.py", line 133, in browse_node
     results = responses.lookup_paginated(path, offset=offset, limit=limit)
   File "/home/conceptnet/conceptnet5/conceptnet5/api.py", line 150, in lookup_paginated
     found = FINDER.lookup(term, limit=(limit + 1), offset=offset)
   File "/home/conceptnet/conceptnet5/conceptnet5/db/query.py", line 142, in lookup
     return self.lookup_assertion(uri)
   File "/home/conceptnet/conceptnet5/conceptnet5/db/query.py", line 194, in lookup_assertion
     cursor = self.connection.cursor()
 psycopg2.InterfaceError: connection already closed

This patch will re-create the connection any time the connection is
closed. Bonus: factor connection creation inside a property called
connection.
@rspeer rspeer merged commit fda1b39 into commonsense:master Sep 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments