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

casync: reuse requests session in RemoteChunkReader #25045

Merged
merged 1 commit into from
Jul 6, 2022
Merged
Changes from all 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
3 changes: 2 additions & 1 deletion system/hardware/tici/casync.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,15 @@ class RemoteChunkReader(ChunkReader):
def __init__(self, url: str) -> None:
super().__init__()
self.url = url
self.session = requests.Session()

def read(self, chunk: Chunk) -> bytes:
sha_hex = chunk.sha.hex()
url = os.path.join(self.url, sha_hex[:4], sha_hex + ".cacnk")

for i in range(CHUNK_DOWNLOAD_RETRIES):
try:
resp = requests.get(url, timeout=CHUNK_DOWNLOAD_TIMEOUT)
resp = self.session.get(url, timeout=CHUNK_DOWNLOAD_TIMEOUT)
break
except Exception:
if i == CHUNK_DOWNLOAD_RETRIES - 1:
Expand Down