Connection getting break while using Flask, RabbitMQ and React
I have created a Flask API ,where it is getting the request from react frontend, and python backend is processing request.The Request is nothing but processing the SQL, which takes times like upto 30 mins, which is correct, since data is in crores.
But After processing the SQL request , at the time of return statement in Python Flask, it is throwing this Error:
Error processing message: Stream connection lost: ConnectionResetError(10054, ‘An existing connection was forcibly closed by the remote host’, None, 10054, None)
Traceback (most recent call last):
File “C:\Users\admin\PycharmProjects\Dexter\consumer.py”, line 41, in on_message_received
ch.basic_publish(exchange=””, routing_key=properties.reply_to,
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
properties=pika.BasicProperties(correlation_id=properties.correlation_id),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
body=json.dumps(response))
^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\admin\PycharmProjects\Dexter.venv1\Lib\site-packages\pika\adapters\blocking_connection.py”, line 2265, in basic_publish
self._flush_output()
~~~~~~~~~~~~~~~~~~^^
File “C:\Users\admin\PycharmProjects\Dexter.venv1\Lib\site-packages\pika\adapters\blocking_connection.py”, line 1353, in _flush_output
self._connection._flush_output(lambda: self.is_closed, *waiters)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\admin\PycharmProjects\Dexter.venv1\Lib\site-packages\pika\adapters\blocking_connection.py”, line 523, in _flush_output
raise self._closed_result.value.error
pika.exceptions.StreamLostError: Stream connection lost: ConnectionResetError(10054, ‘An existing connection was forcibly closed by the remote host’, None, 10054, None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “C:\Users\admin\PycharmProjects\Dexter\consumer.py”, line 74, in
start_consumer()
~~~~~~~~~~~~~~^^
File “C:\Users\admin\PycharmProjects\Dexter\consumer.py”, line 67, in start_consumer
channel.start_consuming()
~~~~~~~~~~~~~~~~~~~~~~~^^
File “C:\Users\admin\PycharmProjects\Dexter.venv1\Lib\site-packages\pika\adapters\blocking_connection.py”, line 1883, in start_consuming
self._process_data_events(time_limit=None)
~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
File “C:\Users\admin\PycharmProjects\Dexter.venv1\Lib\site-packages\pika\adapters\blocking_connection.py”, line 2044, in _process_data_events
self.connection.process_data_events(time_limit=time_limit)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\admin\PycharmProjects\Dexter.venv1\Lib\site-packages\pika\adapters\blocking_connection.py”, line 851, in process_data_events
self._dispatch_channel_events()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
File “C:\Users\admin\PycharmProjects\Dexter.venv1\Lib\site-packages\pika\adapters\blocking_connection.py”, line 567, in _dispatch_channel_events
impl_channel._get_cookie()._dispatch_events()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
File “C:\Users\admin\PycharmProjects\Dexter.venv1\Lib\site-packages\pika\adapters\blocking_connection.py”, line 1510, in _dispatch_events
consumer_info.on_message_callback(self, evt.method,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
evt.properties, evt.body)
^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\admin\PycharmProjects\Dexter\consumer.py”, line 48, in on_message_received
ch.basic_nack(delivery_tag=method.delivery_tag, requeue=False)
~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\admin\PycharmProjects\Dexter.venv1\Lib\site-packages\pika\adapters\blocking_connection.py”, line 2151, in basic_nack
self._impl.basic_nack(
~~~~~~~~~~~~~~~~~~~~~^
delivery_tag=delivery_tag, multiple=multiple, requeue=requeue)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\admin\PycharmProjects\Dexter.venv1\Lib\site-packages\pika\channel.py”, line 401, in basic_nack
self._raise_if_not_open()
~~~~~~~~~~~~~~~~~~~~~~~^^
File “C:\Users\admin\PycharmProjects\Dexter.venv1\Lib\site-packages\pika\channel.py”, line 1403, in _raise_if_not_open
raise exceptions.ChannelWrongStateError(‘Channel is closed.’)
pika.exceptions.ChannelWrongStateError: Channel is closed.
And rabbitmq starts to process the request again.I dont want that also.
Please any solutions.
Read more here: Source link
