EN-3146 Fix S3 upload retry - #16
Open
stepan-mt wants to merge 1 commit into
Open
Conversation
stepan-mt
marked this pull request as ready for review
August 13, 2026 13:55
keosak
approved these changes
Aug 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
EN-3146
Objective
Fix occasional tileset upload fails, namely
RuntimeError: (400, b'')error response to HTTP PUT request when some part/chunk of the ingested file is uploaded to S3 storage.Description
This error happened on servers belonging to Data team. They made a workaround based on containerization of maptiler-cloud-cli. Further investigation showed that invoking HTTP request to s3 storage (https://s3.gra.io.cloud.ovh.net) resolves to IPv6 address when maptiler-cloud-cli is invoked directly. On the other hand, it is resolved to IPv4 address when the tool is run from Docker. As a temporal workaround, Data team added entry in /etc/hosts file to always use IPv4.
However I was not able to reproduce the issue from my machine with IPv6 address, so I concentrated more on the code itself.
The former
upload_to_s3function has used optimizedmemoryviewfor upload parts/chunks. The advantage of this was that there is just one memory allocation for whole ingested file. However when there is urllib error that happens after request was sent (e.g. when reading the response from the socket), retry mechanism (urllib3.util.retry.Retry) re-uses the already exhausted iterator created by formerread(lenght: int)function.The simplest way how to reproduce the error is simply send empty body:
In another words, for some reason servers of our Data team has sometime problem reading the response from OVH s3 server when they are connected via IPv6.
I'm aware that current code is slightly less optimized, because there is 8MB memory allocation for each part/chunk, however same approach is also used in
upload_to_google_drive().Acceptance
I monkey patched the
HTTPConnection.getresponsefunction:Old version of the code:
New version of the code