pywps: Issue session rollback after some errors

Description

After there is an error, if the pywps service receives new request, the error messages are shown as follows:

[pid 21389:tid 140700116551424] 2016-09-02 16:53:15,709 INFO sqlalchemy.engine.base.Engine BEGIN (implicit)
[pid 21389:tid 140700116551424] 2016-09-02 16:53:15,710 INFO sqlalchemy.engine.base.Engine INSERT INTO pywps_requests (uuid, pid, operation, version, time_start, time_end, identifier, message, percent_done, status) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
[pid 21389:tid 140700116551424] 2016-09-02 16:53:15,710 INFO sqlalchemy.engine.base.Engine ('4e206528-70e2-11e6-891d-ecb1d783f730', 21389, 'execute', '1.0.0', '2016-09-02 16:53:15.708929', None, 'OpenWPS:CV_VisualizeNonSeries', None, None, None)
[pid 21389:tid 140700116551424] 2016-09-02 16:53:15,710 INFO sqlalchemy.engine.base.Engine COMMIT
[pid 21389:tid 140700116551424] [remote xxx:30540] mod_wsgi (pid=21389): Exception occurred processing WSGI script '/xxx/pywps/wps.wsgi'.
[pid 21389:tid 140700116551424] [remote xxx:30540] Traceback (most recent call last):
[pid 21389:tid 140700116551424] [remote xxx:30540]   File "/xxx/python2.7/site-packages/werkzeug/wrappers.py", line 291, in application
[pid 21389:tid 140700116551424] [remote xxx:30540]     return f(*args[:-2] + (request,))(*args[-2:])
[pid 21389:tid 140700116551424] [remote xxx:30540]   File "/xxx/python2.7/site-packages/pywps-4.0.0rc1-py2.7.egg/pywps/app/Service.py", line 585, in __call__
[pid 21389:tid 140700116551424] [remote xxx:30540]     request_uuid
[pid 21389:tid 140700116551424] [remote xxx:30540]   File "/xxx/python2.7/site-packages/pywps-4.0.0rc1-py2.7.egg/pywps/app/Service.py", line 297, in execute
[pid 21389:tid 140700116551424] [remote xxx:30540]     tempdir = tempfile.mkdtemp(prefix='pywps_process_', dir=workdir)
[pid 21389:tid 140700116551424] [remote xxx:30540]   File "/xxx/python2.7/tempfile.py", line 333, in mkdtemp
[pid 21389:tid 140700116551424] [remote xxx:30540]     _os.mkdir(file, 0700)
[pid 21389:tid 140700116551424] [remote xxx:30540] OSError: [Errno 13] Permission denied: '/tmp/outputs/pywps_process_OyLFRX'
[pid 21388:tid 140700041606912] [remote xxx:65351] mod_wsgi (pid=21388): Exception occurred processing WSGI script '/xxx/pywps/wps.wsgi'.
[pid 21388:tid 140700041606912] [remote xxx:65351] Traceback (most recent call last):
[pid 21388:tid 140700041606912] [remote xxx:65351]   File "/xxx/python2.7/site-packages/werkzeug/wrappers.py", line 291, in application
[pid 21388:tid 140700041606912] [remote xxx:65351]     return f(*args[:-2] + (request,))(*args[-2:])
[pid 21388:tid 140700041606912] [remote xxx:65351]   File "/xxx/python2.7/site-packages/pywps-4.0.0rc1-py2.7.egg/pywps/app/Service.py", line 573, in __call__
[pid 21388:tid 140700041606912] [remote xxx:65351]     log_request(request_uuid, wps_request)
[pid 21388:tid 140700041606912] [remote xxx:65351]   File "/xxx/python2.7/site-packages/pywps-4.0.0rc1-py2.7.egg/pywps/dblog.py", line 65, in log_request
[pid 21388:tid 140700041606912] [remote xxx:65351]     session.commit()
[pid 21388:tid 140700041606912] [remote xxx:65351]   File "build/bdist.linux-x86_64/egg/sqlalchemy/orm/session.py", line 811, in commit
[pid 21388:tid 140700041606912] [remote xxx:65351]     self.transaction.commit()
[pid 21388:tid 140700041606912] [remote xxx:65351]   File "build/bdist.linux-x86_64/egg/sqlalchemy/orm/session.py", line 396, in commit
[pid 21388:tid 140700041606912] [remote xxx:65351]     self._assert_active(prepared_ok=True)
[pid 21388:tid 140700041606912] [remote xxx:65351]   File "build/bdist.linux-x86_64/egg/sqlalchemy/orm/session.py", line 213, in _assert_active
[pid 21388:tid 140700041606912] [remote xxx:65351]     % self._rollback_exception
[pid 21388:tid 140700041606912] [remote xxx:65351] InvalidRequestError: This Session's transaction has been rolled back due to a previous exception during flush. To begin a new transaction with this Session, first issue Session.rollback(). Original exception was: (sqlite3.ProgrammingError) SQLite objects created in a thread can only be used in that same thread.The object was created in thread id 140700041606912 and this is thread id 140700158510848

Environment

  • operating system: CentOS 6.5 final
  • Python version: 2.7.10
  • PyWPS version: 4.0.0rc1 (cloned on 31 Aug 2016 13:46 UTC+09:00)
  • source/distribution
    • [O] git clone
    • Debian
    • PyPI
    • zip/tar.gz
    • other (please specify):
  • web server
    • [O] Apache/mod_wsgi
    • CGI
    • other (please specify):

Steps to Reproduce

i) changing permission of output directory ii) calling pywps service, then the first error message is shown as ‘permission denied’ ii) re-calling pywps service, then the second error message is shown as ‘InvalidRequestError’

Additional Information

The first error is no problem because I can solve that.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 16 (10 by maintainers)

Most upvoted comments

Just to confirm, I also have this problem. This was not the case in RC1. This commit 5f579d4a353677e9b58375fbda9932dd9f4551e2 seem to have introduced the issue. On top of the InvalidRequestError mentioned above, my apache log is also complaining about:

[Tue Sep 06 17:56:19.488170 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477] mod_wsgi (pid=41): Exception occurred processing WSGI script '/var/www/html/wps/pywps.wsgi'.
[Tue Sep 06 17:56:19.488230 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477] Traceback (most recent call last):
[Tue Sep 06 17:56:19.488249 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477]   File "/usr/local/lib/python2.7/dist-packages/Werkzeug-0.11.11-py2.7.egg/werkzeug/wrappers.py", line 291, in application
[Tue Sep 06 17:56:19.488628 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477]     return f(*args[:-2] + (request,))(*args[-2:])
[Tue Sep 06 17:56:19.488644 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477]   File "/usr/local/lib/python2.7/dist-packages/pywps-4.0.0rc2-py2.7.egg/pywps/app/Service.py", line 573, in __call__
[Tue Sep 06 17:56:19.488827 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477]     log_request(request_uuid, wps_request)
[Tue Sep 06 17:56:19.488844 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477]   File "/usr/local/lib/python2.7/dist-packages/pywps-4.0.0rc2-py2.7.egg/pywps/dblog.py", line 65, in log_request
[Tue Sep 06 17:56:19.488913 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477]     session.commit()
[Tue Sep 06 17:56:19.488929 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477]   File "build/bdist.linux-x86_64/egg/sqlalchemy/orm/session.py", line 811, in commit
[Tue Sep 06 17:56:19.489921 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477]     self.transaction.commit()
[Tue Sep 06 17:56:19.489940 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477]   File "build/bdist.linux-x86_64/egg/sqlalchemy/orm/session.py", line 398, in commit
[Tue Sep 06 17:56:19.489951 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477]     self._prepare_impl()
[Tue Sep 06 17:56:19.489959 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477]   File "build/bdist.linux-x86_64/egg/sqlalchemy/orm/session.py", line 378, in _prepare_impl
[Tue Sep 06 17:56:19.489967 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477]     self.session.flush()
[Tue Sep 06 17:56:19.489976 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477]   File "build/bdist.linux-x86_64/egg/sqlalchemy/orm/session.py", line 2065, in flush
[Tue Sep 06 17:56:19.489984 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477]     self._flush(objects)
[Tue Sep 06 17:56:19.489992 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477]   File "build/bdist.linux-x86_64/egg/sqlalchemy/orm/session.py", line 2183, in _flush
[Tue Sep 06 17:56:19.490000 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477]     transaction.rollback(_capture_exception=True)
[Tue Sep 06 17:56:19.490009 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477]   File "build/bdist.linux-x86_64/egg/sqlalchemy/util/langhelpers.py", line 60, in __exit__
[Tue Sep 06 17:56:19.490467 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477]     compat.reraise(exc_type, exc_value, exc_tb)
[Tue Sep 06 17:56:19.490484 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477]   File "build/bdist.linux-x86_64/egg/sqlalchemy/orm/session.py", line 2147, in _flush
[Tue Sep 06 17:56:19.490493 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477]     flush_context.execute()
[Tue Sep 06 17:56:19.490513 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477]   File "build/bdist.linux-x86_64/egg/sqlalchemy/orm/unitofwork.py", line 386, in execute
[Tue Sep 06 17:56:19.490727 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477]     rec.execute(self)
[Tue Sep 06 17:56:19.490743 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477]   File "build/bdist.linux-x86_64/egg/sqlalchemy/orm/unitofwork.py", line 545, in execute
[Tue Sep 06 17:56:19.490753 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477]     uow
[Tue Sep 06 17:56:19.490782 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477]   File "build/bdist.linux-x86_64/egg/sqlalchemy/orm/persistence.py", line 176, in save_obj
[Tue Sep 06 17:56:19.491182 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477]     mapper, table, insert)
[Tue Sep 06 17:56:19.491197 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477]   File "build/bdist.linux-x86_64/egg/sqlalchemy/orm/persistence.py", line 776, in _emit_insert_statements
[Tue Sep 06 17:56:19.491207 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477]     execute(statement, multiparams)
[Tue Sep 06 17:56:19.491218 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477]   File "build/bdist.linux-x86_64/egg/sqlalchemy/engine/base.py", line 947, in execute
[Tue Sep 06 17:56:19.491867 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477]     return meth(self, multiparams, params)
[Tue Sep 06 17:56:19.491887 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477]   File "build/bdist.linux-x86_64/egg/sqlalchemy/sql/elements.py", line 262, in _execute_on_connection
[Tue Sep 06 17:56:19.493092 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477]     return connection._execute_clauseelement(self, multiparams, params)
[Tue Sep 06 17:56:19.493114 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477]   File "build/bdist.linux-x86_64/egg/sqlalchemy/engine/base.py", line 1055, in _execute_clauseelement
[Tue Sep 06 17:56:19.493124 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477]     compiled_sql, distilled_params
[Tue Sep 06 17:56:19.493133 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477]   File "build/bdist.linux-x86_64/egg/sqlalchemy/engine/base.py", line 1191, in _execute_context
[Tue Sep 06 17:56:19.493140 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477]     context)
[Tue Sep 06 17:56:19.493148 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477]   File "build/bdist.linux-x86_64/egg/sqlalchemy/engine/base.py", line 1386, in _handle_dbapi_exception
[Tue Sep 06 17:56:19.493156 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477]     exc_info
[Tue Sep 06 17:56:19.493163 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477]   File "build/bdist.linux-x86_64/egg/sqlalchemy/util/compat.py", line 202, in raise_from_cause
[Tue Sep 06 17:56:19.493302 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477]     reraise(type(exception), exception, tb=exc_tb, cause=cause)
[Tue Sep 06 17:56:19.493318 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477]   File "build/bdist.linux-x86_64/egg/sqlalchemy/engine/base.py", line 1184, in _execute_context
[Tue Sep 06 17:56:19.493327 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477]     context)
[Tue Sep 06 17:56:19.493338 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477]   File "build/bdist.linux-x86_64/egg/sqlalchemy/engine/default.py", line 462, in do_execute
[Tue Sep 06 17:56:19.493651 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477]     cursor.execute(statement, parameters)
[Tue Sep 06 17:56:19.493744 2016] [wsgi:error] [pid 41:tid 139725325768448] [remote 172.17.0.1:59477] OperationalError: (sqlite3.OperationalError) no such table: pywps_requests [SQL: u'INSERT INTO pywps_requests (uuid, pid, operation, version, time_start, time_end, identifier, message, percent_done, status) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'] [parameters: ('36fe63aa-745b-11e6-968d-0242ac110002', 41, u'describeprocess', u'1.0.0', '2016-09-06 17:56:19.486979', None, u'mywpsprocess', None, None, None)]

@geoslegend Jachym introduced SQLAlchemy to be able to switch to other DMBS, such as postgres. I assume postgres should work out of the box. Can you give it a try? You only need to adjust the parameters in the config file, correct @jachym?

@geoslegend @jonas-eberle so, do I understand it correctly, that moving from sqlite3 to postgres should solve the issue?

@geoslegend please, your report was OK, my comment was regarding PyWPS: PyWPS should report error messages in more readable manner

@jachym See the error message in the last line: Original exception was: (sqlite3.ProgrammingError) SQLite objects created in a thread can only be used in that same thread.The object was created in thread id 140700041606912 and this is thread id 140700158510848

Stackoverflow shows this explanation (“You may not be using threads explicitly, but mod_wsgi is, and you’ve defined a global session object”) and solution: http://stackoverflow.com/a/34010159