Qiskit / qiskit-ibmq-provider

Qiskit Provider for accessing the quantum devices and simulators at IBM Quantum.
Apache License 2.0
243 stars 143 forks source link

Fix websocket connection drop #1090

Closed rathishcholarajan closed 2 years ago

rathishcholarajan commented 2 years ago

Summary

Reset retry counter after every successful connection, ping ws server every minute so connection doesn't drop every few mins.

Details and comments

Fixes issue https://github.com/Qiskit-Partners/qiskit-ibm/issues/209 where ws connection maxes out after 5 retries.

runtime_job._start_websocket_client:WARNING:2021-11-17 02:26:59,893: An error occurred while streaming results from the server for job c6a64nurog3ddsr8gio0:
Traceback (most recent call last):
  File "/opt/conda/lib/python3.8/site-packages/qiskit/providers/ibmq/runtime/runtime_job.py", line 328, in _start_websocket_client
    self._ws_client.job_results()
  File "/opt/conda/lib/python3.8/site-packages/qiskit/providers/ibmq/api/clients/runtime_ws.py", line 74, in job_results
    self.stream(url=url, retries=max_retries, backoff_factor=backoff_factor)
  File "/opt/conda/lib/python3.8/site-packages/qiskit/providers/ibmq/api/clients/base.py", line 211, in stream
    raise WebsocketError(error_message)
qiskit.providers.ibmq.api.exceptions.WebsocketError: 'Max retries exceeded: Failed to establish a websocket connection. Error: Traceback (most recent call last):\n  File "/opt/conda/lib/python3.8/site-packages/websocket/_app.py", line 369, in run_forever\n    dispatcher.read(self.sock.sock, read, check)\n  File "/opt/conda/lib/python3.8/site-packages/websocket/_app.py", line 70, in read\n    if not read_callback():\n  File "/opt/conda/lib/python3.8/site-packages/websocket/_app.py", line 335, in read\n    op_code, frame = self.sock.recv_data_frame(True)\n  File "/opt/conda/lib/python3.8/site-packages/websocket/_core.py", line 396, in recv_data_frame\n    frame = self.recv_frame()\n  File "/opt/conda/lib/python3.8/site-packages/websocket/_core.py", line 435, in recv_frame\n    return self.frame_buffer.recv_frame()\n  File "/opt/conda/lib/python3.8/site-packages/websocket/_abnf.py", line 337, in recv_frame\n    self.recv_header()\n  File "/opt/conda/lib/python3.8/site-packages/websocket/_abnf.py", line 293, in recv_header\n    header = self.recv_strict(2)\n  File "/opt/conda/lib/python3.8/site-packages/websocket/_abnf.py", line 372, in recv_strict\n    bytes_ = self.recv(min(16384, shortage))\n  File "/opt/conda/lib/python3.8/site-packages/websocket/_core.py", line 519, in _recv\n    return recv(self.sock, bufsize)\n  File "/opt/conda/lib/python3.8/site-packages/websocket/_socket.py", line 125, in recv\n    raise WebSocketConnectionClosedException(\nwebsocket._exceptions.WebSocketConnectionClosedException: Connection to remote host was lost.\n'
jyu00 commented 2 years ago

I don't know why the CI is failing, but the code looks good