Affects: 5.3.27


I have already created a stack overflow question, but it seems to be a bug in webflux: https://stackoverflow.com/questions/76629303/webflux-streaming-databuffer-with-zip-resulting-in-corrupt-file

In this example RestController I'm returning a Flux. A ZipOutputStream is writing to the DefaultDataBuffer-OutputStream. In the browser I'm receiving bytes - each time the .map(file -> putZipEntry(file, zipOutputStream)) is executed. But the browser doesn't receive the bytes sent by the .doOnComplete(() -> closeZipOutputStream(zipOutputStream)); method. This creates a corrupt zip file. I have tested this behavior with multiple browsers and also a java client.

@GetMapping(value = "/zip", produces = "application/zip")
  public Flux<DefaultDataBuffer> zip() {
    var files = Arrays.asList("File1", "File2", "File3", "File4", "File5");
    var responseDataBuffer = new DefaultDataBufferFactory().allocateBuffer();
    ZipOutputStream zipOutputStream = new ZipOutputStream(responseDataBuffer.asOutputStream());
    return Flux.fromStream(files.stream())
        .map(file -> putZipEntry(file, zipOutputStream))
        .map(x -> responseDataBuffer)
        .doOnComplete(() -> closeZipOutputStream(zipOutputStream));
  }

  private void closeZipOutputStream(ZipOutputStream zipOutputStream) {
    try {
    zipOutputStream.close();
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }

  private ZipOutputStream putZipEntry(String file, ZipOutputStream zipOutputStream) {
    try {
      zipOutputStream.putNextEntry(new ZipEntry(file + ".txt"));
      zipOutputStream.write(file.getBytes());
      zipOutputStream.closeEntry();
      return zipOutputStream;
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }

Comment From: bclozel

You're getting plenty of support for something that looks like a custom implementation that does not involve Spring, but only Reactor. I'm closing this issue for now and will have a look at the question.

Comment From: wintama-roberto

@bclozel I don't think it is a bug in reactor, as the code is executed correctly by reactor. But the content of the DefaultDataBuffer is not streamed correctly to the client. So it must be a bug in Webflux or netty.