Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WADO-RS download on plain session ConnectionResetError (10054) is not handled #42

Open
sjoerdk opened this issue Jun 29, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@sjoerdk
Copy link
Owner

sjoerdk commented Jun 29, 2023

  • dicomtrolley version: 3.0.0-alpha
  • Python version: 3.7

Description

When performing longer wado-rs operations with a single requests Session object, a ConnectionResetError is raised by urllib3.
This bubbles up and is not handled by dicomtrolley which exits. It should be possible to just retry using a new connection.

What I Did

# start a wado-rs download of a longer (several minutes) download:
session = requests.Session()
wado_rs = WadoRS(session=session, url="http://server/dicomweb/")
wado_rs.datasets(StudyReference(study_uid='123')))  # study taking minutes to download

# then download a second study on the same object
wado_rs.datasets(StudyReference(study_uid='456')))  # any other study

Origin and route the exception takes:

Traceback (most recent call last):
  File "C:\ProgramData\Miniconda3\envs\speedtest\lib\site-packages\urllib3\response.py", line 438, in _error_catcher
    yield
  File "C:\ProgramData\Miniconda3\envs\speedtest\lib\site-packages\urllib3\response.py", line 767, in read_chunked
    chunk = self._handle_chunk(amt)
  File "C:\ProgramData\Miniconda3\envs\speedtest\lib\site-packages\urllib3\response.py", line 720, in _handle_chunk
    returned_chunk = self._fp._safe_read(self.chunk_left)
  File "C:\ProgramData\Miniconda3\envs\speedtest\lib\http\client.py", line 628, in _safe_read
    chunk = self.fp.read(min(amt, MAXAMOUNT))
  File "C:\ProgramData\Miniconda3\envs\speedtest\lib\socket.py", line 589, in readinto
    return self._sock.recv_into(b)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\ProgramData\Miniconda3\envs\speedtest\lib\site-packages\requests\models.py", line 753, in generate
    for chunk in self.raw.stream(chunk_size, decode_content=True):
  File "C:\ProgramData\Miniconda3\envs\speedtest\lib\site-packages\urllib3\response.py", line 572, in stream
    for line in self.read_chunked(amt, decode_content=decode_content):
  File "C:\ProgramData\Miniconda3\envs\speedtest\lib\site-packages\urllib3\response.py", line 793, in read_chunked
    self._original_response.close()
  File "C:\ProgramData\Miniconda3\envs\speedtest\lib\contextlib.py", line 130, in __exit__
    self.gen.throw(type, value, traceback)
  File "C:\ProgramData\Miniconda3\envs\speedtest\lib\site-packages\urllib3\response.py", line 455, in _error_catcher
    raise ProtocolError("Connection broken: %r" % e, e)
urllib3.exceptions.ProtocolError: ("Connection broken: ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None)", 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:\ProgramData\Miniconda3\envs\speedtest\lib\site-packages\dicomtrolley\http.py", line 163, in read_next_chunk
    return next(self._bytes_iterator)
  File "C:\ProgramData\Miniconda3\envs\speedtest\lib\site-packages\dicomtrolley\http.py", line 53, in __next__
    sized_chunk += next(self._chunk_iterator)
  File "C:\ProgramData\Miniconda3\envs\speedtest\lib\site-packages\requests\models.py", line 756, in generate
    raise ChunkedEncodingError(e)
requests.exceptions.ChunkedEncodingError: ("Connection broken: ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None)", ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))
@sjoerdk sjoerdk added the bug Something isn't working label Jun 29, 2023
@sjoerdk
Copy link
Owner Author

sjoerdk commented Jun 29, 2023

There was a very similar issue with rad69. This was worked around by lessening the server load by splitting downloads along series (#11). See 14eb3f4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant