Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resteasy Reactive AsyncFile is never closed #41811

Closed
Mulgish opened this issue Jul 10, 2024 · 8 comments · Fixed by #41824
Closed

Resteasy Reactive AsyncFile is never closed #41811

Mulgish opened this issue Jul 10, 2024 · 8 comments · Fixed by #41824
Labels
area/rest kind/bug Something isn't working
Milestone

Comments

@Mulgish
Copy link

Mulgish commented Jul 10, 2024

Describe the bug

AsyncFile is never closed in Resteasy Reactive HTTP server

Expected behavior

AsyncFile should be closed

Actual behavior

AsyncFile is not closed:
image

How to Reproduce?

  1. Return AsyncFile in Resteasy Reactive route
  2. Put a breakpoint on AsyncFIle#close
  3. Attempt to download the file
  4. Observe that AsyncFIle#close has not been called
  5. (Optional) When testing on an NFS share, try to delete test file and observe .nfsxxxxxxx file being created due to open file handle.
  6. (Optional) Observe that shutting down Quarkus service removes .nfsxxxxxxx file

Reproducer repository

https://github.com/Mulgish/quarkus-issue-41811-reproducer
See README for steps.

Example code

package com.bla;

import io.smallrye.mutiny.Uni;
import io.vertx.core.file.OpenOptions;
import io.vertx.mutiny.core.Vertx;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.Response;


import static jakarta.ws.rs.core.MediaType.*;

@ApplicationScoped
@Path("/downloads")
public class DownloadsEndpoint {

    public static final OpenOptions READ_ONLY = new OpenOptions()
        .setRead(true).setWrite(false);

    @Inject
    Vertx vertx;

    @GET
    @Path("/someFile")
    @Produces(APPLICATION_OCTET_STREAM)
    public Uni<Response> downloadFile() {
        return vertx.fileSystem()
            .open("/tmp/someFile.txt", READ_ONLY)
            .onItem().transform(asyncFile -> Response.ok(asyncFile).build());
    }
}

Output of uname -a or ver

Linux 5.15.146.1-microsoft-standard-WSL2 #1 SMP Thu Jan 11 04:09:03 UTC 2024 x86_64 GNU/Linux

Output of java -version

openjdk version "21.0.3" 2024-04-16 OpenJDK Runtime Environment (Red_Hat-21.0.3.0.9-1) (build 21.0.3+9) OpenJDK 64-Bit Server VM (Red_Hat-21.0.3.0.9-1) (build 21.0.3+9, mixed mode, sharing)

Quarkus version or git rev

3.12.0

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.9.6 (Red Hat 3.9.6-6) Maven home: /usr/share/maven Java version: 21.0.3, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-21-openjdk-21.0.3.0.9-1.fc40.x86_64 Default locale: en_US, platform encoding: UTF-8 OS name: "linux", version: "5.15.146.1-microsoft-standard-wsl2", arch: "amd64", family: "unix"

Additional information

I have noticed this issue because I was getting .nfsxxxxx files created on an NFS share everytime I would delete a file after streaming it with FIlesystem.open call.

Switching to Filesystem.readFIle has fixed the issue but it is not ideal as I can not stream large files to a client.

@Mulgish Mulgish added the kind/bug Something isn't working label Jul 10, 2024
Copy link

quarkus-bot bot commented Jul 10, 2024

/cc @FroMage (resteasy-reactive), @geoand (resteasy-reactive), @stuartwdouglas (resteasy-reactive)

@geoand
Copy link
Contributor

geoand commented Jul 10, 2024

Can you please attach a sample project that shows the problem in action?

@geoand geoand added the triage/needs-reproducer We are waiting for a reproducer. label Jul 10, 2024
@Mulgish
Copy link
Author

Mulgish commented Jul 10, 2024

@geoand Sure, I will need dome time to prepare it.

@geoand
Copy link
Contributor

geoand commented Jul 10, 2024

Thanks!

@mschorsch
Copy link
Contributor

@Mulgish Does this also happen when you return Uni<AsyncFile> instead of Uni<Response>?

@Mulgish
Copy link
Author

Mulgish commented Jul 10, 2024

@Mulgish Does this also happen when you return Uni<AsyncFile> instead of Uni<Response>?

Yes

@Mulgish
Copy link
Author

Mulgish commented Jul 10, 2024

@geoand I have created a reproducer at https://github.com/Mulgish/issue-41811-reproducer.
Please see README file for steps to reproduce.

@geoand
Copy link
Contributor

geoand commented Jul 11, 2024

Thanks a lot!

#41824 fixes the issue

@geoand geoand removed the triage/needs-reproducer We are waiting for a reproducer. label Jul 11, 2024
geoand added a commit that referenced this issue Jul 11, 2024
Properly close AsyncFile in Quarkus REST
@quarkus-bot quarkus-bot bot added this to the 3.13 - main milestone Jul 11, 2024
@gsmet gsmet modified the milestones: 3.13 - main, 3.12.3 Jul 16, 2024
gsmet pushed a commit to gsmet/quarkus that referenced this issue Jul 16, 2024
holly-cummins pushed a commit to holly-cummins/quarkus that referenced this issue Jul 31, 2024
@gsmet gsmet modified the milestones: 3.12.3, 3.8.6 Aug 14, 2024
gsmet pushed a commit to gsmet/quarkus that referenced this issue Aug 14, 2024
danielsoro pushed a commit to danielsoro/quarkus that referenced this issue Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/rest kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants