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

[Httpclient] fix pointer position of mmap object in the case of failure #118

Merged
merged 7 commits into from
Mar 31, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion v3io/dataplane/transport/httpclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ def _send_request_on_connection(self, request, connection):
self.log(
"Tx", connection=connection, method=request.method, path=path, headers=request.headers, body=request.body
)

starting_offset = 0
if request.body is not None and hasattr(request.body, "seek") and hasattr(request.body, "tell"):
starting_offset = request.body.tell()
try:
try:
connection.request(request.method, path, request.body, request.headers)
Expand All @@ -166,6 +168,11 @@ def _send_request_on_connection(self, request, connection):
connection=connection,
)
connection.close()
if request.body and hasattr(request.body, "seek") and hasattr(request.body, "tell"):
tomerm-iguazio marked this conversation as resolved.
Show resolved Hide resolved
# If the first connection fails, the pointer of the body might move at the size
# of the first connection blocksize.
# We need to reset the position of the pointer in order to send the whole file.
request.body.seek(starting_offset)
connection = self._create_connection(self._host, self._ssl_context)
request.transport.connection_used = connection
connection.request(request.method, path, request.body, request.headers)
Expand Down
Loading