Truncated protobufs in Micronaut application

Viewed 258

I have a Micronaut (version 2.1.4) application that consumes Protobuf messages via HTTP.

This is the controller example:

@Post
@Consumes(ProtobufferCodec.PROTOBUFFER_ENCODED)
@Produces(ProtobufferCodec.PROTOBUFFER_ENCODED)
public HttpResponse<MyResponse> ingestData(@Body byte[] body)
  throws InvalidProtocolBufferException {

        MyProto myOjbect = MyProto.parseFrom(body);
        MyResponse responseBody = myService.processData(body);
        return HttpResponse.ok(responseBody);
}

My problem is that, only for some requests (not all of them), the line MyProto.parseFrom(body) raises an exception

om.google.protobuf.InvalidProtocolBufferException: While parsing a protocol message, the input ended unexpectedly in the middle of a field.  This could mean either that the input has been truncated or that an embedded message misreported its own length.
    at com.google.protobuf.InvalidProtocolBufferException.truncatedMessage(InvalidProtocolBufferException.java:84)
    at com.google.protobuf.CodedInputStream$ArrayDecoder.pushLimit(CodedInputStream.java:1189)
    at com.google.protobuf.CodedInputStream$ArrayDecoder.readMessage(CodedInputStream.java:886)
    ...
    at com.google.protobuf.AbstractParser.parsePartialFrom(AbstractParser.java:158)
    at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:191)
    at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:203)
    at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:208)
    at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:48)
....

And the exception is right, the body (byte[]) came truncated (not complete) and with a different length from the one, I've sent via CURL. I also verified that the value coming in the Content-Length header is different from the length of the byte[] (protobuf), in the way that the length of the byte[] is smaller.

I'm not able to reproduce this issue, only happens in production.

Any idea?

"Feelings":

  • It happens with big requests
  • Maybe Netty has some parameter that, even if the request is allowed by size, it's truncated, chopped, or similar and that affects the protobuf (byte[])
  • Performance (memory) problems?

More information:

  • io.micronaut:micronaut-bom:2.1.4
  • io.micronaut:micronaut-http-server-netty
  • io.micronaut.grpc:micronaut-protobuff-support:1.0.1
0 Answers
Related