tapir icon indicating copy to clipboard operation
tapir copied to clipboard

[BUG] Server should return 400 Bad request if not all body bytes received

Open akozich opened this issue 1 year ago • 2 comments

Tapir version: 1.11.7

Scala version: 3.5.0

Our endpoint receives the PUT request with JSON body from mobile clients. As mobile network may be unstable some requests are interrupted before receiving the full request body.

We set NettyConfig.requestTimeout to 5s to make sure we close the connection from the server side. Then channel is marked inactive. When org.playframework.netty.HandlerPublisher receives channelInactive it completes by calling SimpleSubscriber.onComplete which sends all received bytes. As a result corrupted JSON is passed to the Codec.

What is the problem?

I'd propose if the number of bytes received is lower than the expected content length do not pass the bytes to the codec

akozich avatar Nov 14 '24 11:11 akozich

Yeah this sounds like a bug, I suppose it should call .onError with a timeout exception?

Would you be able to create a PR maybe?

adamw avatar Nov 18 '24 08:11 adamw

@akozich I've prepared a draft #4214 where I've tried to reproduce the issue. Could you please confirm if that test NettyCatsRequestTimeoutTest shows your scenario?

sergiuszkierat avatar Dec 19 '24 17:12 sergiuszkierat