FastAPI在Docker Swarm中无法传递几千字节以上的响应。

huangapple go评论50阅读模式
英文:

FastAPI in dockerswarm fails to deliver responses over a few kilobytes

问题

我有一个使用Traefik通过Docker Swarm部署的FastAPI服务。一切都正常,直到我请求一个应该返回一个稍大于10 KB的JSON文件的端点。对这个端点的调用需要好几分钟才返回一个空字符串,同时返回一个状态码200。我检查了所有可以找到的日志,看起来FastAPI完成了请求,而且立刻返回了状态码200。它应该将响应发送到我Swarm中的不同节点上托管的Traefik反向代理,然后由代理将其转发给客户端。然而,看起来响应在传输过程中丢失了,在客户端没有收到预期的JSON文件,而是收到一个空字符串。

你有没有遇到过这种情况?是否有参数可以设置Docker Swarm网络以处理这种数据(对我来说它似乎并不太重)?任何帮助将不胜感激,非常感谢!

我尝试过更改端点名称,使用标准的Docker和Traefik部署服务(它完全正常工作),返回较小的JSON文件(对于非常小的JSON文件也正常工作)。我已经没有其他选择了 FastAPI在Docker Swarm中无法传递几千字节以上的响应。

英文:

I have a FastAPI service that I deploy with traefik via docker swarm. Everything runs fine until I request an endpoint supposed to return a JSON file just over 10 Ko. The call to this endpoint take several minutes before returning an empty string along with a 200 status code. I've checked all the logs I could find, and it looks like FastAPI completes the request properly and instantly (thus the 200 status code). It should send the response to my traefik reverse proxy hosted on a different node on my swarm, that would forward it to the client. However it looks like the response is lost somewhere on the way, and the client never get the expected JSON file, and gets an empty string instead.

Has this ever happened to you ? Is there a parameter to set for docker swarm networks to be handled this kind of data (it doesnt seem that heavy to me) ? Any help would be greatly appreciated, thanks a lot !

I tried changing the endpoint name, deploying the service with standard docker and traefik (it works perfectly), returning a smaller JSON file (works well with very small JSONs). I'm out of options FastAPI在Docker Swarm中无法传递几千字节以上的响应。

答案1

得分: 2

这是由于GCP基础设施托管我的Swarm引起的。

GCP提供的VPC具有1460的MTU(最大传输单元),而Docker网络默认为1500。因此,发送到我的反向代理的数据包一旦超过1460字节,就会被丢弃。

英文:

To answer my own question - If anyone stumbles unto this: this was caused due to the GCP infrastructure hosting my swarm.

The VPC provided by GCP had a MTU (Max transmission Unit) of 1460, where docker network defaults to 1500. The package sent to my reverse proxy was thus dropped as soon as it was bigger than 1460 bytes.

huangapple
  • 本文由 发表于 2023年2月16日 04:10:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/75464987.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定