From 88a758236a5e3f8b282fd67aa090b4c150c6846f Mon Sep 17 00:00:00 2001 From: ejona Date: Fri, 13 Jun 2014 11:50:18 -0700 Subject: [PATCH] Deframer.deframe returns number of unprocessed bytes. This is intended to reduce the flakiness of test_TestServiceBenchmarks. TAP showed some flaky runs where HttpStreamDeframer threw the exception "GRPC stream not correctly aligned". ------------- Created by MOE: http://code.google.com/p/moe-java MOE_MIGRATED_REVID=69166650 --- .../net/stubby/transport/InputStreamDeframer.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/com/google/net/stubby/transport/InputStreamDeframer.java b/core/src/main/java/com/google/net/stubby/transport/InputStreamDeframer.java index e793aadf94..cc8817357d 100644 --- a/core/src/main/java/com/google/net/stubby/transport/InputStreamDeframer.java +++ b/core/src/main/java/com/google/net/stubby/transport/InputStreamDeframer.java @@ -22,15 +22,17 @@ public class InputStreamDeframer extends Deframer { /** * Deframing a single input stream that contains multiple GRPC frames + * + * @return the number of unconsumed bytes remaining in the buffer */ @Override public int deframe(InputStream frame, Operation target) { try { - int read = 0; - while (frame.available() > 0) { - read += super.deframe(frame, target); - } - return read; + int remaining; + do { + remaining = super.deframe(frame, target); + } while (frame.available() > 0); + return remaining; } catch (IOException ioe) { throw new RuntimeException(ioe); }