I have a pretty standard Vapor http server, It has a middleware where it inspects the request body and does some authentication validation.
func respond(to request: Request, chainingTo next: Responder) -> EventLoopFuture<Response> {
var myStuff: SomeCommonPattern? = try request.content.decode(SomeCommonPattern?.self)
SomeCommonPattern is a base class for all other requests in the group. That works very well in debug on Mac. When I run this in docker on my Mac laptop it still works as expected. I put it through a rigorous tests with a hundred clients making simultaneous requests for hours. Not a single failure. Now I moved the same docker image to a production machine, which is Ubuntu with lover specs than my machine, and my code still works with exception when it does not. About 1 request out of 5 fails to decode the request. I put some additional logging and sure enough, sometimes request.body.string is empty when most other same requests are fine. Anyone knows what could be happening ? It looks almost like the body of the request is still in transit when the middleware is being called. It happens even when I make requests from a single client.
Edit: I just realized that on my laptop the service is running directly, while on the linux machine it is behind apache 2 reverse proxy. It is probably a significant detail but I still do not know the reason of the intermittent behavior.
Edit 2: I moved the failing code out of the middleware and put in every endpoint implementation. It is much less convenient and more error prone but now my application works 100% of the time. That may confirm that apache is off the hook and the problem is indeed in Vapor, or my misunderstanding how to use it.