From 6b93d560bb56eafa0b53b30f03e075c37c544f58 Mon Sep 17 00:00:00 2001 From: Greg Leach Date: Thu, 13 Nov 2014 15:41:39 -0800 Subject: [PATCH] If the emitter is closed while processing data, then just eat the remaining data - don't throw an exception, as this is a valid case. --- AndroidAsync/src/com/koushikdutta/async/Util.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/AndroidAsync/src/com/koushikdutta/async/Util.java b/AndroidAsync/src/com/koushikdutta/async/Util.java index c065b5201..e8f6f43e5 100644 --- a/AndroidAsync/src/com/koushikdutta/async/Util.java +++ b/AndroidAsync/src/com/koushikdutta/async/Util.java @@ -34,7 +34,12 @@ public static void emitAllData(DataEmitter emitter, ByteBufferList list) { throw new RuntimeException("mDataHandler failed to consume data, yet remains the mDataHandler."); } } - if (list.remaining() != 0 && !emitter.isPaused()) { + if (list.remaining() != 0 && handler == null) { + // The emitter was closed or cancelled while processing data. Lets just eat the remaining. + System.out.println("emitter: " + emitter); + list.recycle(); + } + else if (list.remaining() != 0 && !emitter.isPaused()) { // not all the data was consumed... // call byteBufferList.recycle() or read all the data to prevent this assertion. // this is nice to have, as it identifies protocol or parsing errors.