xxdwpl opened a new issue #2601:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2601
**版本:**
1.3.2
**背景:**
服务端需要流式返回音频数据,采用http chunk方式传输。
客户端接收音频数据后播放,播放存在取消操作,也就是数据接收一部分之后,客户端会存在`response.close()`操作。
服务端在catch到Pipe closed异常后,会取消后续的业务操作,节省资源。
发现在客户端连续取消8次后,第9次请求客户端无法接收到response数据,等待约50s后,服务恢复正常,可以继续请求。
代码如下
```
// 服务端接口代码
public ResponseEntity<InputStream> serviceIntf(@RequestBody ...) {
PipedInputStream inputStream = service.executBusiness(...);
return ResponseEntity.ok().header(HttpHeaders.CONTENT_TYPE,
"application/octet-stream").body(inputStream);
}
// 服务端启动异步线程做业务处理,并写入数据到outputStream,最后关闭流
public InputStream executBusiness(...) {
PipedOutputStream outputStream = new PipedOutputStream();
PipedInputStream inputStream = new PipedInputStream(outputStream, 64 *
1024);
threadPoolTaskExecutor.execute(() -> {
try {
...
outputStream.write(audioData);
outputStream.flush();
} catch (IOException e) {
// 客户端主动关闭连接,取消后续业务处理
if ("Pipe closed".equals(e.getMessage())) {
cancelBusinessProcess();
}
} finally {
outputStream.close();
}
});
}
```
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]