[@sanity/client] running a script with Bun gets the process hanged.
raulfdm opened this issue · comments
If you find a security vulnerability, do NOT open an issue. Email security@sanity.io instead.
Describe the bug
Running a simple script using the @sanity/client
with bun gets the process hanging forever. This doesn't work with tsx
.
To Reproduce
Steps to reproduce the behavior:
- Access this repository https://github.com/devraul/bun-sanity-process-hang
- Clone it
- Follow the README instructions
- See error
Expected behavior
Works with bun without problems
Screenshots
CleanShot.2024-04-10.at.07.03.28.mp4
Which versions of Sanity are you using?
Run sanity versions
in the terminal and copy-paste the result here.
What operating system are you using?
"@sanity/client": "6.15.11"
Which versions of Node.js / npm are you running?
❯ bun --revision
1.1.3+2615dc742
Additional context
Since this is an integration problem, I opened the same problem in Bun. Maybe they need to fix something in their side:
oven-sh/bun#10138
Interesting. I got it working in an earlier version of bun (v1.0.17
to be specific), but seeing the same behavior as you when switching to bun v1.1.3
)
Interesting take @bjoerge . I tested each version and it stopped working on v1.1.0. I'll add this comment there
Looks like it could be related to this: oven-sh/bun#7260
Hi, we tried adding bun
conditions in https://github.com/sanity-io/client/releases/tag/v6.15.12 that redirected bun to use the node
version of get-it
, which uses node:http
and node:https
under the hood as transport instead of global.fetch
.
It created different problems:
- https://github.com/sanity-io/get-it/blob/1c17809502af0fffdeaefd1b19d87d69c98c34e6/src/request/node-request.ts#L198-L199
- https://github.com/sanity-io/client/actions/runs/8647489271/job/23709097678
![image](https://private-user-images.githubusercontent.com/81981/321672095-fca1c777-3b2a-4405-9100-f8b62d2b8fe2.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTkzOTI1NzYsIm5iZiI6MTcxOTM5MjI3NiwicGF0aCI6Ii84MTk4MS8zMjE2NzIwOTUtZmNhMWM3NzctM2IyYS00NDA1LTkxMDAtZjhiNjJkMmI4ZmUyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MjYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjI2VDA4NTc1NlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWEwNGQ5OGVlN2FkZTgzOGYzZDcxZDI0MjE3MDA5NDVjNTE0YTliMmI0ODBkZTg5NTUzZTJlYjQ3NzM4ZDhmZDMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.gPg6Ss6MbjWtkg_ZTATjX5deAvmx8W03psRtU9Zg5IY)
Surprisingly, changing the bun import conditions to point to the transport that uses fetch
appears to solve it:
It's surprising because the assumption has been that bun
has used the worker
condition until now and always used fetch
under the hood.
Here's the basic e2e test we're using:
https://github.com/sanity-io/client/blob/main/runtimes/bun/client.fetch.test.js
The CI tests on Bun 1.1.3, and I've also run the same test locally with Bun 1.1.3 and it works there too.
Give https://github.com/sanity-io/client/releases/tag/v6.15.13 and tell us if that works for you 🙌
Checking the test rig, it started happening last week:
https://github.com/sanity-io/client-runtimes-compatibility/actions/runs/8516205488/job/23324913908
- @sanity/client@6.15.7
- bun@1.1.0
Last passing test: https://github.com/sanity-io/client-runtimes-compatibility/actions/runs/8502608803/job/23287010458
- @sanity/client@6.15.7
- 1.0.36
Based on this, and the error on the CLI that started happening with Bun 1.1.0 seems to be it started using the node version of get-it
and @sanity/client
indeed.
Here's how you can check what transport is in use:
import {unstable__adapter, unstable__environment} from '@sanity/client'
import {adapter, environment} from 'get-it'
console.log({unstable__adapter, unstable__environment, adapter, environment})
In bun prior to 1.1.0 adapter
reports fetch
, afterwards it started using node
🤔
In any case that shouldn't be a problem anymore as we now tell Bun exactly what version to use
Closing as it should be fixed as of @sanity/client@6.15.13
Really nice. Thank you for fixing this 🙌