Flask+IIS环境大文件上传后sendMetadata请求失败求助
排查思路
1. 核对IIS核心配置细节
- 确认
web.config中httpRuntime节点参数:maxRequestLength需设为4194304(对应4GB,单位KB),executionTimeout调至足够大(如3600),避免请求因处理超时被中断:<httpRuntime maxRequestLength="4194304" executionTimeout="3600" /> - 检查请求过滤模块的
maxAllowedContentLength(单位字节,4GB对应4294967296),确保配置生效:<security> <requestFiltering> <requestLimits maxAllowedContentLength="4294967296" /> </requestFiltering> </security> - 查看IIS的ARR代理配置,确认
proxyTimeout、responseBufferLimit未设过小,且未对sendMetadata的请求路径设置隐性限制。
2. 调整Waitress服务器参数
- 启动Waitress时增加连接超时、存活时间及线程数配置,避免大文件上传耗尽连接池:
waitress-serve --listen=*:8080 --timeout=300 --keepalive=60 --threads=10 your_app:app - 查看Waitress日志,排查是否存在
Connection reset by peer、Timeout等连接相关错误,确认Waitress是否正常接收sendMetadata请求。
3. 检查Windows系统网络限制
- 用
netsh int tcp show global查看TCP参数,调整端口复用及超时:netsh int tcp set global maxuserport=65534 netsh int tcp set global tcptimedwaitdelay=30 - 检查Windows防火墙、本地安全策略,确认未限制
w3wp.exe、Waitress进程的连接数或请求大小。
4. 排查Flask异步任务的资源占用
- 确认异步处理文件的实现方式(线程/进程/Celery),若为线程池,检查是否因大文件处理耗尽线程,导致无法响应新请求。
- 用任务监视器监控CPU、内存使用率,确认大文件合并后,服务器资源未被占满,Flask进程仍有空闲资源处理
sendMetadata请求。 - 检查异步任务是否存在阻塞操作(如同步IO、未释放的锁),避免阻塞Waitress工作线程。
5. 对比请求差异并抓包分析
- 对比
sendMetadata与pingServer的请求细节:请求方法、请求头、请求体大小,确认sendMetadata是否携带过大请求体或异常请求头。 - 用Fiddler/Wireshark抓包,确认
sendMetadata请求状态:- 若请求未到达服务器:排查IIS代理的路由规则、端口转发是否异常;
- 若请求到达但无响应:检查Flask路由是否因资源不足未处理,或响应被IIS缓存/拦截。
- 前端手动为
sendMetadata的fetch请求设置更长超时:const controller = new AbortController(); const timeoutId = setTimeout(() => controller.abort(), 60000); fetch('/send-metadata', { method: 'POST', body: metadata, signal: controller.signal }).finally(() => clearTimeout(timeoutId));
内容的提问来源于stack exchange,提问作者Dan Shepherd
相关产品推荐
相关产品推荐

