Attempted read from closed stream

Hello, I have an issue implementing file downloader using vaadin 14. The data is streamed from spring-boot backend service through API call. Below is the sample API that called as data provider,

@PostMapping(value = "/download", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE) public ResponseEntity<InputStreamResource> downloadFile( @RequestBody DownloadRequest request ) { ... return response; }

then here is Vaadin looks like for downloading file

`actionButton.addClickListener(event → {
String fileName = StringUtils.join(filename, “.csv”);

  downloadAnchor.setHref(new StreamResource(fileName, () -> {
    try {
      return getStreamResource() // do API call to backend
    } catch (IOException e) {
      throw new RuntimeException(e);

and below is the error when anchor was clicked

Attempted read from closed stream