TotoroChen opened a new issue #2035: URL: https://github.com/apache/servicecomb-java-chassis/issues/2035
使用https://github.com/apache/servicecomb-java-chassis/blob/master/integration-tests/it-producer/src/main/java/org/apache/servicecomb/it/schema/DownloadSchema.java中提供的pipeInputStream方式实现下载功能: @ApiResponses({@ApiResponse(code = 200, response = File.class, message = "")}) @GetMapping(path = "/slowInputStream") public ResponseEntity<InputStream> slowInputStream() throws IOException { PipedInputStream in = new PipedInputStream(); PipedOutputStream out = new PipedOutputStream(); in.connect(out); slowInputStreamThread = new Thread(() -> { Thread.currentThread().setName("download thread"); byte[] bytes = "1".getBytes(); for (; ; ) { try { out.write(bytes); out.flush(); Thread.sleep(1000); } catch (Throwable e) { break; } } try { out.close(); } catch (final IOException ioe) { // ignore } }); slowInputStreamThread.start(); ResponseEntity<InputStream> responseEntity = ResponseEntity .ok() .header(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN_VALUE) .header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=slowInputStream.txt") .body(in); return responseEntity; } } 现像: web上多次下载,然后又取消下载,出现如下报错,一直无法恢复。 java.io.IOException: Pipe closed at java.io.PipedInputStream.checkStateForReceive(PipedInputStream.java:260) at java.io.PipedInputStream.receive(PipedInputStream.java:226) at java.io.PipedOutputStream.write(PipedOutputStream.java:149) 2020-11-02 11:54:22,430 [vertx-blocked-thread-checker] WARN io.vertx.core.impl.BlockedThreadChecker - {Thread Thread[vert.x-worker-thread-15,5,main] has been blocked for 1452652508 ms, time limit is 60000 ms} io.vertx.core.VertxException: Thread blocked at java.lang.Object.wait(Native Method) at java.io.PipedInputStream.read(PipedInputStream.java:326) at java.io.PipedInputStream.read(PipedInputStream.java:377) at java.io.InputStream.read(InputStream.java:101) at org.apache.servicecomb.foundation.vertx.stream.InputStreamToReadStream$ReadResult.doRead(InputStreamToReadStream.java:105) at org.apache.servicecomb.foundation.vertx.stream.InputStreamToReadStream.readInWorker(InputStreamToReadStream.java:126) at org.apache.servicecomb.foundation.vertx.stream.InputStreamToReadStream$$Lambda$4329/1533402502.handle(Unknown Source) at io.vertx.core.impl.ContextImpl.lambda$executeBlocking$2(ContextImpl.java:272) at io.vertx.core.impl.ContextImpl$$Lambda$4332/1524655426.run(Unknown Source) at io.vertx.core.impl.TaskQueue.run(TaskQueue.java:76) at io.vertx.core.impl.TaskQueue$$Lambda$75/1696328858.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) 请问这种情况是什么原因,难道代码写错了? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
