Open Paultje52 opened 11 months ago
I am seeing the same thing. Tried await request.json()
and await Bun.readableStreamToJSON(request.body as ReadableStream)
which all behaved the same way. A few more things I've noticed:
fetch()
from the browser never worked and always hangsfetch()
from node randomly sometimes works, but mostly hangscurl -X POST
from local bash showed a more reliable pattern where the first time it would hang, but subsequent requests would all succeed.Has there been any update on this topic? I have experienced this for the first time yesterday. Sadly I can't use all the nice Bun features if a POST request/response doesn't work with it.
Thank you for an update on this matter. :)
I did some more investigating. The same result @fiffty describes also happens with request.body.getReader
. When using the following code, the request hangs for the first time.
const reader = event.request.body.getReader();
const chunks = [];
while(true) {
const { value, done } = await reader.read();
console.log({ value, done });
if (done) {
break;
}
chunks.push(...value);
}
console.log("request body: ", Buffer.from(chunks).toString());
There is just one console log.
{
value: Buffer(26) [ 123, 13, 10, 32, 32, 32, 32, 34, 104, 101, 108, 108, 111, 34, 58, 32, 34, 119, 111, 114, 108, 100, 34, 13, 10, 125 ],
done: false,
}
However, the second time the request does go through. This is the log of the second time.
{
value: Buffer(26) [ 123, 13, 10, 32, 32, 32, 32, 34, 104, 101, 108, 108, 111, 34, 58, 32, 34, 119, 111, 114, 108, 100, 34, 13, 10, 125 ],
done: false,
}
{
value: undefined,
done: true,
}
request body: {
"hello": "world"
}
That means that there is something wrong in Bun's ReadableStreamDefaultReader
. Looking into the v1.0.4-v1.0.5 changes, I saw that 6301778
changed a couple of things regarding streams. I don't know if this is the reason why ReadableStreamReaders are broken, but maybe this is a helpfull nudge in the right direction @Electroid?
The new 17 update seems to have resolved this issue. It is now working fine for me.
Okay, somehow it is still not fixed. Yesterday evening everything worked fine without any workarounds. Now I am logging in to the same setup and it doesnt work anymore. Very strange.
Same error for me but with more details:
bun --bun run dev
:
const body = await request.json();
hang indefinitely
console.log(request)
give me that :
Request (0 KB) {
method: "POST",
url: "http://test.REDACTED/hooks/release",
headers: Headers {
"host": "test.REDACTED",
"user-agent": "newreleases/1.18.1-be681b9",
"content-length": "198",
"accept-encoding": "gzip",
"authorization": "Basic REDACTED",
"content-type": "application/json; charset=utf-8",
"x-forwarded-for": "REDACTED",
"x-forwarded-host": "test.REDACTED",
"x-forwarded-proto": "https",
"x-newreleases-signature": "95f4b791d7001a70305297e09d7a9606d4538d23e09530477a73cd1e32b342e7",
"x-newreleases-timestamp": "1703090236",
}
ReadableStream {
locked: [Getter],
cancel: [Function: cancel],
getReader: [Function: getReader],
pipeTo: [Function: pipeTo],
pipeThrough: [Function: pipeThrough],
tee: [Function: tee],
values: [Function: values],
[Symbol(Symbol.asyncIterator)]: [Function: lazyAsyncIterator],
}
}
bun --bun run vite build
with @catdadcode/svelte-adapter-bun
and then bun ./build/index.js
:
const body = await request.json();
crash immediately with :
console.log(request)
give me that :
Request (0 KB) {
method: "POST",
url: "https://test.REDACTED/hooks/release",
headers: Headers {
"host": "test.REDACTED",
"user-agent": "newreleases/1.18.1-be681b9",
"content-length": "199",
"accept-encoding": "gzip",
"authorization": "Basic REDACTED",
"content-type": "application/json; charset=utf-8",
"x-forwarded-for": "REDACTED",
"x-forwarded-host": "test.REDACTED",
"x-forwarded-proto": "https",
"x-newreleases-signature": "1834d76ac4d9b861a8547a710f70e3edbfeb972c19b6588ffe6c1692479a0d90",
"x-newreleases-timestamp": "1703092199",
}
}
npm run dev
:
const body = await request.json();
work perfectly
console.log(request)
give me that :
Request {
[Symbol(realm)]: { settingsObject: { baseUrl: undefined } },
method: 'POST',
localURLsOnly: false,
unsafeRequest: false,
body: { stream: undefined, source: null, length: null },
client: { baseUrl: undefined },
reservedClient: null,
replacesClientId: '',
window: 'client',
keepalive: false,
serviceWorkers: 'all',
initiator: '',
destination: '',
priority: null,
origin: 'client',
policyContainer: 'client',
referrer: 'client',
referrerPolicy: '',
mode: 'cors',
useCORSPreflightFlag: true,
credentials: 'same-origin',
useCredentials: false,
cache: 'default',
redirect: 'follow',
integrity: '',
cryptoGraphicsNonceMetadata: '',
parserMetadata: '',
reloadNavigation: false,
historyNavigation: false,
userActivation: false,
taintedOrigin: false,
redirectCount: 0,
responseTainting: 'basic',
preventNoCacheCacheControlHeaderModification: false,
done: false,
timingAllowFailed: false,
headersList: HeadersList {
cookies: null,
},
urlList: [ [URL] ],
url: URL {
href: 'http://test.REDACTED/hooks/release',
origin: 'http://test.REDACTED',
protocol: 'http:',
username: '',
password: '',
host: 'test.REDACTED',
hostname: 'test.REDACTED',
port: '',
pathname: '/hooks/release',
search: '',
searchParams: URLSearchParams {},
hash: ''
}
},
[Symbol(signal)]: AbortSignal { aborted: false },
[Symbol(headers)]: HeadersList {
cookies: null,
[Symbol(headers map)]: Map(11) {
'host' => [Object],
'user-agent' => [Object],
'content-length' => [Object],
'accept-encoding' => [Object],
'authorization' => [Object],
'content-type' => [Object],
'x-forwarded-for' => [Object],
'x-forwarded-host' => [Object],
'x-forwarded-proto' => [Object],
'x-newreleases-signature' => [Object],
'x-newreleases-timestamp' => [Object]
},
}
}
vite build
with @sveltejs/adapter-node
and then node ./build/index.js
:
const body = await request.json();
work perfectly
console.log(request)
give me that :
Request {
[Symbol(realm)]: { settingsObject: { baseUrl: undefined } },
method: 'POST',
localURLsOnly: false,
unsafeRequest: false,
body: { stream: undefined, source: null, length: null },
client: { baseUrl: undefined },
reservedClient: null,
replacesClientId: '',
window: 'client',
keepalive: false,
serviceWorkers: 'all',
initiator: '',
destination: '',
priority: null,
origin: 'client',
policyContainer: 'client',
referrer: 'client',
referrerPolicy: '',
mode: 'cors',
useCORSPreflightFlag: true,
credentials: 'same-origin',
useCredentials: false,
cache: 'default',
redirect: 'follow',
integrity: '',
cryptoGraphicsNonceMetadata: '',
parserMetadata: '',
reloadNavigation: false,
historyNavigation: false,
userActivation: false,
taintedOrigin: false,
redirectCount: 0,
responseTainting: 'basic',
preventNoCacheCacheControlHeaderModification: false,
done: false,
timingAllowFailed: false,
headersList: HeadersList {
cookies: null,
},
urlList: [ [URL] ],
url: URL {
href: 'https://test.REDACTED/hooks/release',
origin: 'https://test.REDACTED',
protocol: 'https:',
username: '',
password: '',
host: 'test.REDACTED',
hostname: 'test.REDACTED',
port: '',
pathname: '/hooks/release',
search: '',
searchParams: URLSearchParams {},
hash: ''
}
},
[Symbol(signal)]: AbortSignal { aborted: false },
[Symbol(headers)]: HeadersList {
cookies: null,
[Symbol(headers map)]: Map(11) {
'host' => [Object],
'user-agent' => [Object],
'content-length' => [Object],
'accept-encoding' => [Object],
'authorization' => [Object],
'content-type' => [Object],
'x-forwarded-for' => [Object],
'x-forwarded-host' => [Object],
'x-forwarded-proto' => [Object],
'x-newreleases-signature' => [Object],
'x-newreleases-timestamp' => [Object]
},
}
}
It seem that bun doesn't receive or process all of the request and give these error (this is just a guess I am not a expert)
Same issue with vite build
with @sveltejs/adapter-node
but this time I run bun ./build/index.js
:
const body = await request.json();
hang indefinitely
console.log(request)
give me that :
Request (0 KB) {
method: "POST",
url: "https://test.REDACTED/hooks/release",
headers: Headers {
"host": "test.REDACTED",
"user-agent": "newreleases/1.18.1-be681b9",
"content-length": "198",
"accept-encoding": "gzip",
"authorization": "Basic REDACTED",
"content-type": "application/json; charset=utf-8",
"x-forwarded-for": "REDACTED",
"x-forwarded-host": "test.REDACTED",
"x-forwarded-proto": "https",
"x-newreleases-signature": "9221223e4fac56b7f1337aa8ba726f5a1a119073fc45108ebf108bc818dcf518",
"x-newreleases-timestamp": "1703154047",
}
ReadableStream {
locked: [Getter],
cancel: [Function: cancel],
getReader: [Function: getReader],
pipeTo: [Function: pipeTo],
pipeThrough: [Function: pipeThrough],
tee: [Function: tee],
values: [Function: values],
[Symbol(Symbol.asyncIterator)]: [Function: lazyAsyncIterator],
}
}
Same problem. request.json() does not resolve it. I created a simple project to reproduce the problem, but I couldn't. It only occurs in my real project.
With the zip provided here I can't reproduce it either.
In my case the problem occurs with macOS arm64:
System:
OS: macOS 14.2
CPU: (10) arm64 Apple M2 Pro
Memory: 120.92 MB / 32.00 GB
Shell: 5.9 - /usr/local/bin/zsh
Binaries:
Node: 18.19.0 - ~/n/bin/node
Yarn: 4.0.2 - ~/n/bin/yarn
npm: 10.2.3 - ~/n/bin/npm
bun: 1.0.18 - ~/.bun/bin/bun
Browsers:
Chrome: 120.0.6099.129
Edge: 120.0.2210.89
Safari: 17.2
npmPackages:
@sveltejs/adapter-auto: ^3.0.1 => 3.0.1
@sveltejs/adapter-node: ^2.0.1 => 2.0.1
@sveltejs/kit: ^2.0.4 => 2.0.4
@sveltejs/vite-plugin-svelte: ^3.0.1 => 3.0.1
svelte: ^4.2.8 => 4.2.8
vite: ^5.0.10 => 5.0.10
Has there been any progress on this topic? :)
What version of Bun is running?
1.0.5 - 1.0.21
What platform is your computer?
Linux 5.4.0-156-generic x86_64 x86_64
What steps can reproduce the bug?
I have a sveltekit project (using vite). I'm running it using
bun --bun run dev
. Here is a zip file that reproduces the issue: sveltekit-bun-body-issue.zipWhen using
--bun
to force vite to use bun's runtime, the promise ofrequest.json()
orrequest.text()
isn't resolved.I see the
1
in the console, but no the2
. Omitting--bun
does work.What is the expected behavior?
To read the body and resolve the promise
What do you see instead?
The promise doesn't get resolved, coursing the request to eventually time out. I don't know if the body is read successfully.
Additional information
When building and then running the project, the body is read successfully. It's just the
vite dev
that doesn't work.