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

Express post request with transfer-encoding chuncked has no body #8638

Open
co-sic opened this issue Feb 2, 2024 · 10 comments
Open

Express post request with transfer-encoding chuncked has no body #8638

co-sic opened this issue Feb 2, 2024 · 10 comments
Assignees
Labels
bug Something isn't working

Comments

@co-sic
Copy link

co-sic commented Feb 2, 2024

What version of Bun is running?

1.0.25, 1.1.8

What platform is your computer?

Linux 6.5.0-15-generic x86_64 x86_64

What steps can reproduce the bug?

I'm running express and apollo-server (latest versions) and i am having the problem that the body of an incomming post request is empty in certain situations. I narrowed it down to the "transfer-encoding": "chuncked" header beeing present and/or the 'content-lenght' header beeing not present. If tried the same failing request and send it through a proxy first (ngrok) and then it worked. You can see the diff of the requests here https://www.diffchecker.com/0AdUpa8R/ (Left side is failing, right side is working).

What is the expected behavior?

No response

What do you see instead?

No response

Additional information

No response

@co-sic co-sic added the bug Something isn't working label Feb 2, 2024
@Electroid Electroid added the needs repro Needs an example to reproduce label Feb 2, 2024
@Electroid
Copy link
Contributor

Thanks for reporting, mind sharing some code to reproduce this issue?

@co-sic
Copy link
Author

co-sic commented Feb 3, 2024

Hey @Electroid i added a example here to reproduce this: https://github.com/co-sic/bun-playground/tree/cosmo-bun-apollo-server

@ambergristle
Copy link

ambergristle commented Feb 4, 2024

Hi! I've potentially run into a similar issue.

I use Docker to build a Next.js (14.0.3) app running on Bun (oven/bun:1.0-slim). I use App Router to GET some data from a third party (Marketstack), and return it to the client.

The third party service responds with chunk-encoded data. When deployed (on Railway, via Docker) large (e.g., ~400 rows) responses fail on json parse (SyntaxError: Unexpected end of JSON). Small (~30 rows) responses work ok both locally and in deployment. Locally (via Docker), the app mostly has no issue; I've been able to repro a couple times, but I'm not sure how. Deploying with Node instead of Bun seems to work regardless of response size.

I added a log of the response before json parse, and those (larger) responses that fail log a size of 0kb, while responses that are (ultimately) parsed ok have a non-zero size.

Source code from the jshttp lib seems to make its way into the error logs (if left uncaught).

I'm wondering whether this has anything to do with:

Here's a permalink to the failing point in my repo. I'm currently working on a more contained/easily-reproducible example.

@ambergristle
Copy link

Locally (via Docker), the app mostly has no issue; I've been able to repro a couple times, but I'm not sure how. Deploying with Node instead of Bun seems to work regardless of response size.

I just discovered that using bun --bun run dev locally is breaking. Works fine (locally) with bun dev and bun run dev.

  const response = await fetch(url)
    .then(async (res) => {
      if (res.ok) {
        return res.json()
      }
    })
    
// results in:
    
 ⨯ SyntaxError: Unexpected end of JSON input
    at json (native)
    at <anonymous> (:20:28)
    at <anonymous> (:18:55)
    at processTicksAndRejections (:61:39)
 ⨯ SyntaxError: Unexpected end of JSON input
    at json (native)
    at <anonymous> (:20:28)
    at <anonymous> (:18:55)
    at processTicksAndRejections (:61:39)
digest: "1774337577"

@co-sic
Copy link
Author

co-sic commented Feb 7, 2024

Hey @Electroid any chance on getting a fix (or even workaround) for this soon? Sorry for the ping, but this is currently blocking and i need to consider to maybe move my bun production service back to node again if it will take a longer time to fix.

@co-sic
Copy link
Author

co-sic commented May 17, 2024

I just check and the issue is still there with bun v1.1.8

@RobinVanCauter
Copy link

RobinVanCauter commented Jun 11, 2024

We've seen this issue as well while building an express backend using bun as the runtime for an existing client (so we can't change the way it's performing its requests).

So def. still an issue with Bun v1.1.12

When ran through node it works fine.

@vitalyavolyn
Copy link

Still an issue in bun 1.1.29 :( I have to use node for now

@Jarred-Sumner Jarred-Sumner removed the needs repro Needs an example to reproduce label Oct 1, 2024
@vitalyavolyn
Copy link

Here's a tiny repro repo: https://github.com/vitalyavolyn/bun-chunked-repro

@Jarred-Sumner
Copy link
Collaborator

I believe this PR will fix it - #14384, but it's not going to be easy to merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants