google-code-export / protostuff

Automatically exported from code.google.com/p/protostuff
Apache License 2.0
1 stars 1 forks source link

IOUtil.mergeDelimitedFrom() reports truncated message on stream EOF reached #62

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hello.

I'm implementing RPC client-server, that is using ProtoStuff for message 
serialization. I read and write messages to socket streams directly by 
ProtoStuff without using intermediate buffers.

Today I noticed that when client gracefully closes connection socket, Protobuff 
throws exception ProtobufException.truncatedMessage(). I traced the problem to 
this piece of code:

    static <T> void mergeDelimitedFrom(InputStream in, byte[] buf, T message, 
            Schema<T> schema, boolean decodeNestedMessageAsGroup) throws IOException
    {
        final int size = in.read();
        if(size == -1)
            throw ProtobufException.truncatedMessage();

I suggest to have different exceptions when the message is really malformed and 
when EOF is discovered *before* first byte of the message is read from stream. 
At least could we please have a way to tell these different situations apart? 

The problem is, for example, that graceful disconnect doesn't need to be 
logged. But malformed message surely should. If logging everything, it pollutes 
logs a bit.

Of course we can read a message to byte buffer first and them deserialize it 
from there, but if ProtoStuff is so skillful to make even that for us, why 
bother? :)

I thought of comparing error messages, but ERR_TRUNCATED_MESSAGE is a private 
member ;)

Original issue reported on code.google.com by Vladisla...@gmail.com on 10 Apr 2011 at 5:33

GoogleCodeExporter commented 9 years ago
EofException could be used (lemme think more about this).
Btw, are you using a single connection for multiple requests 
(multiplexing/pipelining)?

PS Im travelling atm ... replies will take longer than usual.

Original comment by david.yu...@gmail.com on 12 Apr 2011 at 6:52

GoogleCodeExporter commented 9 years ago
Currently I'm using thread-per-connection model. For my current project that's 
what I need. But since my little RPC is pluggable, in the next one I plan to 
add components to use Netty. But that won't be soon ;)

>PS Im travelling atm ... replies will take longer than usual.
No problem. That's no hurry.

Original comment by Vladisla...@gmail.com on 12 Apr 2011 at 8:21

GoogleCodeExporter commented 9 years ago
I only wanted to outline that when EOF is detected before reading first byte of 
object from stream, it's one situation. But when the same EOF is detected in 
the middle of the object reading from stream - it's completely another one.

The first one is actually more or less legitimate (depending on software), but 
the second one is a definite error in almost all cases. So users should have a 
chance to handle those two differently, I think.

Original comment by Vladisla...@gmail.com on 12 Apr 2011 at 9:59

GoogleCodeExporter commented 9 years ago
Now that I'm back I'll try to iron these issues out as soon as I can.
I'm currently working on improving streaming support w/c can work very well 
with vanilla jrapidrpc.  More details to come once its ready.

Original comment by david.yu...@gmail.com on 27 Jun 2011 at 2:16

GoogleCodeExporter commented 9 years ago
Thanks, David ;)

Original comment by Vladisla...@gmail.com on 27 Jun 2011 at 2:26

GoogleCodeExporter commented 9 years ago
Fixed at rev 1334.
// exception thrown will be:
throw new EOFException("mergeDelimitedFrom");

Cheers

Original comment by david.yu...@gmail.com on 7 Jul 2011 at 9:35