You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2018/08/17 00:51:33 UTC

[incubator-servicecomb-java-chassis] branch master updated: [SCB-845] bug fix: some times download file can not get correct content

This is an automated email from the ASF dual-hosted git repository.

liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git


The following commit(s) were added to refs/heads/master by this push:
     new 2594548  [SCB-845] bug fix: some times download file can not get correct content
2594548 is described below

commit 2594548d512120752f3c229b76f105e57706979c
Author: wujimin <wu...@huawei.com>
AuthorDate: Thu Aug 16 00:08:10 2018 +0800

    [SCB-845] bug fix: some times download file can not get correct content
---
 .../servicecomb/foundation/vertx/http/ReadStreamPart.java  | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/http/ReadStreamPart.java b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/http/ReadStreamPart.java
index bb922b2..caf2887 100644
--- a/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/http/ReadStreamPart.java
+++ b/foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/http/ReadStreamPart.java
@@ -106,10 +106,16 @@ public class ReadStreamPart extends AbstractPart {
     CompletableFuture<T> future = new CompletableFuture<>();
     Buffer buffer = Buffer.buffer();
 
-    readStream.exceptionHandler(future::completeExceptionally);
-    readStream.handler(buffer::appendBuffer);
-    readStream.endHandler(v -> future.complete(converter.apply(buffer)));
-    readStream.resume();
+    // if readStream.resume() not run on correct eventloop, will:
+    //  1.create a context task to save last chunk data to buffer
+    //  2.activate connection to read new data
+    //  but maybe 2 will run before 1, that will cause lost data or get incorrect data
+    context.runOnContext(V -> {
+      readStream.exceptionHandler(future::completeExceptionally);
+      readStream.handler(buffer::appendBuffer);
+      readStream.endHandler(v -> future.complete(converter.apply(buffer)));
+      readStream.resume();
+    });
 
     return future;
   }