nakagami/CyMySQL

BrokenPipeError: [Errno 32] Broken pipe

MufidJamaluddin opened this issue · 1 comments

Broken pipe error occurs when the flask application is relatively busy. Then, we need to manually restart the application or handle the recovery of the application in code. Could you fix this error and add an automatically recover feature on the production server? I struggled with this never-ending production error.

App 3411705 output: [ pid=3411705, time=2020-06-28 07:15:12,677 ]: Exception on /api/auth [POST]
App 3411705 output: Traceback (most recent call last):
App 3411705 output:   File "/home/guidecit/virtualenv/essayscoringapp/3.7/lib/python3.7/site-packages/cymysql/cursors.py", line 130, in execute
App 3411705 output:     self._query(query)
App 3411705 output:   File "/home/guidecit/virtualenv/essayscoringapp/3.7/lib/python3.7/site-packages/cymysql/cursors.py", line 240, in _query
App 3411705 output:     conn.query(q)
App 3411705 output:   File "/home/guidecit/virtualenv/essayscoringapp/3.7/lib/python3.7/site-packages/cymysql/connections.py", line 343, in query
App 3411705 output:     self._execute_command(COMMAND.COM_QUERY, sql)
App 3411705 output:   File "/home/guidecit/virtualenv/essayscoringapp/3.7/lib/python3.7/site-packages/cymysql/connections.py", line 440, in _execute_command
App 3411705 output:     self.socket.sendall(prelude + sql)
App 3411705 output: BrokenPipeError: [Errno 32] Broken pipe
App 3411705 output: 
App 3411705 output: During handling of the above exception, another exception occurred:
App 3411705 output: 
App 3411705 output: Traceback (most recent call last):
App 3411705 output:   File "/home/guidecit/virtualenv/essayscoringapp/3.7/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1284, in _execute_context
App 3411705 output:     cursor, statement, parameters, context
App 3411705 output:   File "/home/guidecit/virtualenv/essayscoringapp/3.7/lib/python3.7/site-packages/sqlalchemy/engine/default.py", line 590, in do_execute
App 3411705 output:     cursor.execute(statement, parameters)
App 3411705 output:   File "/home/guidecit/virtualenv/essayscoringapp/3.7/lib/python3.7/site-packages/cymysql/cursors.py", line 135, in execute
App 3411705 output:     self.errorhandler(exc, value)
App 3411705 output:   File "/home/guidecit/virtualenv/essayscoringapp/3.7/lib/python3.7/site-packages/cymysql/cursors.py", line 37, in errorhandler
App 3411705 output:     self.connection.errorhandler(self, errorclass, errorvalue)
App 3411705 output:   File "/home/guidecit/virtualenv/essayscoringapp/3.7/lib/python3.7/site-packages/cymysql/connections.py", line 115, in errorhandler
App 3411705 output:     raise Error(errorclass, errorvalue)
App 3411705 output: cymysql.err.Error: (<class 'BrokenPipeError'>, BrokenPipeError(32, 'Broken pipe'))
App 3411705 output: 
App 3411705 output: The above exception was the direct cause of the following exception:
App 3411705 output: 
App 3411705 output: Traceback (most recent call last):
App 3411705 output:   File "/home/guidecit/virtualenv/essayscoringapp/3.7/lib/python3.7/site-packages/flask/app.py", line 2311, in wsgi_app
App 3411705 output:     response = self.full_dispatch_request()
App 3411705 output:   File "/home/guidecit/virtualenv/essayscoringapp/3.7/lib/python3.7/site-packages/flask/app.py", line 1834, in full_dispatch_request
App 3411705 output:     rv = self.handle_user_exception(e)
App 3411705 output:   File "/home/guidecit/virtualenv/essayscoringapp/3.7/lib/python3.7/site-packages/flask/app.py", line 1737, in handle_user_exception
App 3411705 output:     reraise(exc_type, exc_value, tb)
App 3411705 output:   File "/home/guidecit/virtualenv/essayscoringapp/3.7/lib/python3.7/site-packages/flask/_compat.py", line 36, in reraise
App 3411705 output:     raise value
App 3411705 output:   File "/home/guidecit/virtualenv/essayscoringapp/3.7/lib/python3.7/site-packages/flask/app.py", line 1832, in full_dispatch_request
App 3411705 output:     rv = self.dispatch_request()
App 3411705 output:   File "/home/guidecit/virtualenv/essayscoringapp/3.7/lib/python3.7/site-packages/flask/app.py", line 1818, in dispatch_request
App 3411705 output:     return self.view_functions[rule.endpoint](**req.view_args)
App 3411705 output:   File "/home/guidecit/virtualenv/essayscoringapp/3.7/lib/python3.7/site-packages/flask/views.py", line 88, in view
App 3411705 output:     return self.dispatch_request(*args, **kwargs)
App 3411705 output:   File "/home/guidecit/virtualenv/essayscoringapp/3.7/lib/python3.7/site-packages/flask/views.py", line 158, in dispatch_request
App 3411705 output:     return meth(*args, **kwargs)
App 3411705 output:   File "ujian_app/api/auth.py", line 53, in ujian_app.api.auth.AuthAPI.post
App 3411705 output:   File "ujian_app/repository/genericrepository.py", line 33, in ujian_app.repository.genericrepository.GenericRepository.find_by_id
App 3411705 output:   File "/home/guidecit/virtualenv/essayscoringapp/3.7/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 1021, in get
App 3411705 output:     return self._get_impl(ident, loading.load_on_pk_identity)
App 3411705 output:   File "/home/guidecit/virtualenv/essayscoringapp/3.7/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 1138, in _get_impl
App 3411705 output:     return db_load_fn(self, primary_key_identity)
App 3411705 output:   File "/home/guidecit/virtualenv/essayscoringapp/3.7/lib/python3.7/site-packages/sqlalchemy/orm/loading.py", line 287, in load_on_pk_identity
App 3411705 output:     return q.one()
App 3411705 output:   File "/home/guidecit/virtualenv/essayscoringapp/3.7/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 3436, in one
App 3411705 output:     ret = self.one_or_none()
App 3411705 output:   File "/home/guidecit/virtualenv/essayscoringapp/3.7/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 3405, in one_or_none
App 3411705 output:     ret = list(self)
App 3411705 output:   File "/home/guidecit/virtualenv/essayscoringapp/3.7/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 3481, in __iter__
App 3411705 output:     return self._execute_and_instances(context)
App 3411705 output:   File "/home/guidecit/virtualenv/essayscoringapp/3.7/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 3506, in _execute_and_instances
App 3411705 output:     result = conn.execute(querycontext.statement, self._params)
App 3411705 output:   File "/home/guidecit/virtualenv/essayscoringapp/3.7/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1020, in execute
App 3411705 output:     return meth(self, multiparams, params)
App 3411705 output:   File "/home/guidecit/virtualenv/essayscoringapp/3.7/lib/python3.7/site-packages/sqlalchemy/sql/elements.py", line 298, in _execute_on_connection
App 3411705 output:     return connection._execute_clauseelement(self, multiparams, params)
App 3411705 output:   File "/home/guidecit/virtualenv/essayscoringapp/3.7/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1139, in _execute_clauseelement
App 3411705 output:     distilled_params,
App 3411705 output:   File "/home/guidecit/virtualenv/essayscoringapp/3.7/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1324, in _execute_context
App 3411705 output:     e, statement, parameters, cursor, context
App 3411705 output:   File "/home/guidecit/virtualenv/essayscoringapp/3.7/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1518, in _handle_dbapi_exception
App 3411705 output:     sqlalchemy_exception, with_traceback=exc_info[2], from_=e
App 3411705 output:   File "/home/guidecit/virtualenv/essayscoringapp/3.7/lib/python3.7/site-packages/sqlalchemy/util/compat.py", line 178, in raise_
App 3411705 output:     raise exception
App 3411705 output:   File "/home/guidecit/virtualenv/essayscoringapp/3.7/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1284, in _execute_context
App 3411705 output:     cursor, statement, parameters, context
App 3411705 output:   File "/home/guidecit/virtualenv/essayscoringapp/3.7/lib/python3.7/site-packages/sqlalchemy/engine/default.py", line 590, in do_execute
App 3411705 output:     cursor.execute(statement, parameters)
App 3411705 output:   File "/home/guidecit/virtualenv/essayscoringapp/3.7/lib/python3.7/site-packages/cymysql/cursors.py", line 135, in execute
App 3411705 output:     self.errorhandler(exc, value)
App 3411705 output:   File "/home/guidecit/virtualenv/essayscoringapp/3.7/lib/python3.7/site-packages/cymysql/cursors.py", line 37, in errorhandler
App 3411705 output:     self.connection.errorhandler(self, errorclass, errorvalue)
App 3411705 output:   File "/home/guidecit/virtualenv/essayscoringapp/3.7/lib/python3.7/site-packages/cymysql/connections.py", line 115, in errorhandler
App 3411705 output:     raise Error(errorclass, errorvalue)
App 3411705 output: sqlalchemy.exc.DBAPIError: (cymysql.err.Error) (<class 'BrokenPipeError'>, BrokenPipeError(32, 'Broken pipe'))
App 3411705 output: [SQL: SELECT akun.nama AS akun_nama, akun.username AS akun_username, akun.password AS akun_password, akun.`role` AS akun_role 
App 3411705 output: FROM akun 
App 3411705 output: WHERE akun.username = %s]
App 3411705 output: [parameters: ... ]
App 3411705 output: (Background on this error at: http://sqlalche.me/e/dbapi)
App 3411705 output: [ pid=3411705, time=2020-06-28 07:15:14,350 ]: Exception on /api/auth [POST]
App 3411705 output: Traceback (most recent call last):
App 3411705 output:   File "/home/guidecit/virtualenv/essayscoringapp/3.7/lib/python3.7/site-packages/cymysql/cursors.py", line 130, in execute
App 3411705 output:     self._query(query)
App 3411705 output:   File "/home/guidecit/virtualenv/essayscoringapp/3.7/lib/python3.7/site-packages/cymysql/cursors.py", line 240, in _query
App 3411705 output:     conn.query(q)
App 3411705 output:   File "/home/guidecit/virtualenv/essayscoringapp/3.7/lib/python3.7/site-packages/cymysql/connections.py", line 343, in query
App 3411705 output:     self._execute_command(COMMAND.COM_QUERY, sql)
App 3411705 output:   File "/home/guidecit/virtualenv/essayscoringapp/3.7/lib/python3.7/site-packages/cymysql/connections.py", line 440, in _execute_command
App 3411705 output:     self.socket.sendall(prelude + sql)
App 3411705 output: BrokenPipeError: [Errno 32] Broken pipe

Driver can't avoid a broken pipe when the query takes too long.