{"record":{"id":"488b88e0965368c1","repo":"XX-net/XX-Net","slug":"download-size-d-need-size-d-download-fail-488b88","errorCode":null,"errorMessage":"download size:%d, need size:%d, download fail.","messagePattern":"download size:(.+?), need size:(.+?), download fail\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"code/default/launcher/download_modules.py","lineNumber":70,"sourceCode":"                file_size = int(req.getheader(b'Content-Length', 0))\n\n                left = file_size\n                downloaded = 0\n                with open(filename, 'wb') as fp:\n                    while True:\n                        chunk_len = min(65536, left)\n                        if not chunk_len:\n                            break\n\n                        chunk = req.read(chunk_len)\n                        if not chunk:\n                            break\n                        fp.write(chunk)\n                        downloaded += len(chunk)\n                        left -= len(chunk)\n\n            if downloaded != file_size:\n                xlog.warn(\"download size:%d, need size:%d, download fail.\", downloaded, file_size)\n                os.remove(filename)\n                continue\n            else:\n                if sha256 and sha256 != hash_file_sum(filename):\n                    xlog.warn(\"donwload %s checksum fail.\", filename)\n                    return False\n                else:\n                    xlog.info(\"download %s to %s success.\", org_url, filename)\n                    return True\n        except Exception as e:\n            xlog.exception(\"download %s to %s fail:%r\", org_url, filename, e)\n            continue\n    xlog.warn(\"download %s fail\", org_url)\n\n\ndef download_unzip(url, extract_path):\n    if os.path.isdir(extract_path):\n        return True","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/XX-net/XX-Net/blob/cfa5bc17b67676e467f37ec50766127e0ab5f0aa/code/default/launcher/download_modules.py#L52-L88","documentation":"download_file() finished the HTTP read loop but the number of bytes written does not match the expected file size, so the download is considered incomplete/truncated; the partial file is deleted and the next mirror is tried.","triggerScenarios":"Server closes the connection early, proxy or GFW interference truncates the transfer, disk fills mid-write, or Content-Length mismatch — resulting in downloaded != file_size.","commonSituations":"Downloading XX-Net modules through an unstable proxy where the stream is cut off, a mirror serving truncated files, or insufficient disk space.","solutions":["Retry — the function already loops to the next URL/mirror; run the download again","Check disk space: df -h in the download directory","Use a different/more reliable download URL or download directly with a browser and place the file manually","Disable or switch the proxy used for the download if transfers keep truncating"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"import shutil, os\nif shutil.disk_usage(download_dir).free < expected_size * 2:\n    raise RuntimeError('insufficient disk space for download')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Retry downloads on size mismatch (the code already moves to the next URL)","Verify disk space before large downloads","Use stable mirrors and a reliable proxy for transfers"],"tags":["network","download","truncation","retry"],"backgroundTag":"incomplete-download","analyzedSha":"cfa5bc17b67676e467f37ec50766127e0ab5f0aa","analyzedAt":"2026-08-27T19:28:28.225Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}