Skip to content

Commit

Permalink
client: fix upload timeouts when sock_read is set
Browse files Browse the repository at this point in the history
Start the sock_read timeout handler after the payload body has been fully written.
  • Loading branch information
dtrifiro committed Jan 12, 2023
1 parent 1202f64 commit 2c8c17b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES/7149.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
changed ``sock_read`` timeout to start after writing has finished, to avoid read timeouts caused by an unfinished write. -- by :user:`dtrifiro`
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Dan Xu
Daniel García
Daniel Grossmann-Kavanagh
Daniel Nelson
Daniele Trifirò
Danny Song
David Bibb
David Michael Brown
Expand Down
4 changes: 3 additions & 1 deletion aiohttp/client_proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ def set_response_params(
self._skip_payload = skip_payload

self._read_timeout = read_timeout
self._reschedule_timeout()

self._timeout_ceil_threshold = timeout_ceil_threshold

Expand Down Expand Up @@ -193,6 +192,9 @@ def _reschedule_timeout(self) -> None:
else:
self._read_timeout_handle = None

def start_timeout(self) -> None:
self._reschedule_timeout()

def _on_read_timeout(self) -> None:
exc = ServerTimeoutError("Timeout on reading data from socket")
self.set_exception(exc)
Expand Down
2 changes: 2 additions & 0 deletions aiohttp/client_reqrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,8 @@ async def write_bytes(
protocol.set_exception(exc)
except Exception as exc:
protocol.set_exception(exc)
else:
protocol.start_timeout()
finally:
self._writer = None

Expand Down
5 changes: 5 additions & 0 deletions tests/test_client_proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,15 @@ async def test_empty_data(loop: Any) -> None:
async def test_schedule_timeout(loop: Any) -> None:
proto = ResponseHandler(loop=loop)
proto.set_response_params(read_timeout=1)
assert proto._read_timeout_handle is None
proto.start_timeout()
assert proto._read_timeout_handle is not None


async def test_drop_timeout(loop: Any) -> None:
proto = ResponseHandler(loop=loop)
proto.set_response_params(read_timeout=1)
proto.start_timeout()
assert proto._read_timeout_handle is not None
proto._drop_timeout()
assert proto._read_timeout_handle is None
Expand All @@ -123,6 +126,7 @@ async def test_drop_timeout(loop: Any) -> None:
async def test_reschedule_timeout(loop: Any) -> None:
proto = ResponseHandler(loop=loop)
proto.set_response_params(read_timeout=1)
proto.start_timeout()
assert proto._read_timeout_handle is not None
h = proto._read_timeout_handle
proto._reschedule_timeout()
Expand All @@ -133,6 +137,7 @@ async def test_reschedule_timeout(loop: Any) -> None:
async def test_eof_received(loop: Any) -> None:
proto = ResponseHandler(loop=loop)
proto.set_response_params(read_timeout=1)
proto.start_timeout()
assert proto._read_timeout_handle is not None
proto.eof_received()
assert proto._read_timeout_handle is None

0 comments on commit 2c8c17b

Please sign in to comment.