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

[nima] content is not sent if using OutputStream #6651

Closed
wojtask9 opened this issue Apr 19, 2023 · 4 comments
Closed

[nima] content is not sent if using OutputStream #6651

wojtask9 opened this issue Apr 19, 2023 · 4 comments
Assignees
Labels
Níma Helidon Níma triage

Comments

@wojtask9
Copy link
Contributor

wojtask9 commented Apr 19, 2023

Environment Details

  • Helidon Version: 4.0.0-ALPHA6
  • Helidon SE
  • JDK version: OpenJDK 64-Bit Server VM Temurin-20+36 (build 20+36, mixed mode, sharing)
  • OS: Linux

Problem Description

When content length is less than 512 bytes then output is wrongly send to client.

Steps to reproduce

test:

public void routing(HttpRouting.Builder routing) {

        int LENGTH = 511;

        routing.get("/test_stream", (req, res) -> {
            String content ="a".repeat(LENGTH);

            InputStream in = new ByteArrayInputStream(content.getBytes());
            in.transferTo(res.outputStream());
        });

        routing.get("/test_string", (req, res) -> {
            String content ="a".repeat(LENGTH);

            res.send(content.getBytes());
        });
}

output:

send not using OutputStream

curl -k -i  -X GET https://localhost:8080/test_string
HTTP/1.1 200 OK
Date: Wed, 19 Apr 2023 13:31:16 +0200
Connection: keep-alive
Content-Length: 511

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

send using OutputStream

curl -k -i  -X GET https://localhost:8080/test_stream
HTTP/1.1 200 OK
Date: Wed, 19 Apr 2023 13:31:13 +0200
Connection: keep-alive
Content-Length: 0

When we increase LENGTH to 512 everything works correct.

@wojtask9 wojtask9 changed the title [nima] content is not send if using OutputStream [nima] content is not sent if using OutputStream Apr 19, 2023
@wojtask9
Copy link
Contributor Author

not sure if this problem is related to #6501

@m0mus m0mus added the triage label Apr 20, 2023
@m0mus m0mus added the Níma Helidon Níma label Apr 20, 2023
@spericas
Copy link
Member

@wojtask9 Could you try explicitly flushing the output stream? There's new buffering to avoid some problems. See #6509.

@wojtask9
Copy link
Contributor Author

@spericas

OutputStream os = res.outputStream();
in.transferTo(os);
os.flush();

With explicit flush everything works :)

@spericas
Copy link
Member

@wojtask9 I will create a PR to do auto-flushing at the end for convenience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Níma Helidon Níma triage
Projects
Archived in project
Development

No branches or pull requests

3 participants