Merge pull request #17608 from sihyeonn/fix/sh-prevent-memory-leaks-on-ollama
fix: prevent memory leaks in file handling and HTTP connections
This commit is contained in:
1 file changed
+5
-3
@@ -1694,13 +1694,15 @@ async def download_file_stream(
|
|||||||
yield f'data: {{"progress": {progress}, "completed": {current_size}, "total": {total_size}}}\n\n'
|
yield f'data: {{"progress": {progress}, "completed": {current_size}, "total": {total_size}}}\n\n'
|
||||||
|
|
||||||
if done:
|
if done:
|
||||||
file.seek(0)
|
file.close()
|
||||||
|
|
||||||
|
with open(file_path, "rb") as file:
|
||||||
chunk_size = 1024 * 1024 * 2
|
chunk_size = 1024 * 1024 * 2
|
||||||
hashed = calculate_sha256(file, chunk_size)
|
hashed = calculate_sha256(file, chunk_size)
|
||||||
file.seek(0)
|
|
||||||
|
|
||||||
url = f"{ollama_url}/api/blobs/sha256:{hashed}"
|
url = f"{ollama_url}/api/blobs/sha256:{hashed}"
|
||||||
response = requests.post(url, data=file)
|
with requests.Session() as session:
|
||||||
|
response = session.post(url, data=file, timeout=30)
|
||||||
|
|
||||||
if response.ok:
|
if response.ok:
|
||||||
res = {
|
res = {
|
||||||
|
|||||||
Reference in new issue
Block a user