{"record":{"id":"1cf7dd91d1766931","repo":"XX-net/XX-Net","slug":"download-size-d-need-size-d-download-fail","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/gae_proxy/local/download_gae_lib.py","lineNumber":88,"sourceCode":"                file_size = int(req.getheader('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                xlog.info(\"download %s to %s success.\", org_url, filename)\n                return True\n        except Exception as e:\n            xlog.warn(\"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\n\n    data_root = os.path.join(top_path, 'data')\n    download_path = os.path.join(data_root, 'downloads')\n    if not os.path.isdir(download_path):","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/XX-net/XX-Net/blob/cfa5bc17b67676e467f37ec50766127e0ab5f0aa/code/default/gae_proxy/local/download_gae_lib.py#L70-L106","documentation":"Logged after a download loop when the number of bytes written to disk does not match the expected file size reported by the server. The partial file is deleted and the retry loop continues; failure of all attempts is reported by the caller.","triggerScenarios":"download_file(url, filename) completes its chunk loop but `downloaded != file_size`: server closed the connection early, Content-Length mismatch, or proxy interrupted the stream.","commonSituations":"Flaky network through the local proxy, GAE IP reset mid-transfer, antivirus/disk issues truncating writes, server misreporting Content-Length.","solutions":["Check network stability / retry with a different proxy IP","Verify the URL returns a correct Content-Length (curl -I)","Upgrade/download the library files manually and place them in the target path","Inspect xlog for the paired exception message to see the underlying socket error"],"exampleFix":"// before\nif not download_file(url, dfn):\n    xlog.warn(\"download file %s fail.\", url)\n\n// after - pre-verify and retry externally, or place file manually\nif not download_file(url, dfn):\n    xlog.warn(\"download file %s fail.\", url)\n    # manually download url and unzip into extract_path, then restart","handlingStrategy":"retry","validationCode":"import os\n# ensure target dir writable and disk has room before triggering lib download\nassert os.access(download_path, os.W_OK) and shutil.disk_usage(download_path).free > file_size_expect * 2","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep the download directory writable with free disk space","Run check_lib_or_download on a stable network or pre-install libs manually"],"tags":["download","size-mismatch","network","gae-proxy"],"backgroundTag":"incomplete-download","analyzedSha":"cfa5bc17b67676e467f37ec50766127e0ab5f0aa","analyzedAt":"2026-08-27T19:28:28.225Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}