oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.79k stars 2.73k forks source link

Segmentation fault SIGSEGV (Address boundary error) working with streams #8810

Closed KilianB closed 6 months ago

KilianB commented 8 months ago

What version of Bun is running?

1.0.26

What platform is your computer?

Microsoft Windows NT 10.0.22621.0 x64

What steps can reproduce the bug?

clone https://github.com/KilianB/elysia/tree/SIGSEGV

bun example/http.ts

What is the expected behavior?

No crash

What do you see instead?

Just the word "Segmentation fault" being printed and the script crashing.

When running bun dev the error message is a bit longer.

error: script "dev" was terminated by signal SIGSEGV (Address boundary error)

Additional information

I can't really isolate the issue. I am in the process to address https://github.com/elysiajs/elysia/issues/332 & https://github.com/elysiajs/elysia/issues/456 and clone Request objects and need to split streams. Due to the nested handlers I was not able to reproduce the issue in isolation.

Jarred-Sumner commented 8 months ago

This isn't quite enough to reproduce the error. What request should be sent? What body should be sent?

KilianB commented 8 months ago

Yes you are correct. Sorry I didn't include the changes when pushing to the new branch. Please check the linked github repo again. Running bun example/http.ts in the above code will now fail.

Please also be advised that the current version of elysia does not throw the same error. You actually need to clone the repository.

niieani commented 8 months ago

I've had this happen to me but in different circumstances. It's happening intermittently. My script just reads and writes some JSON files asynchronously. Has nothing to do with http in my case. Running it again and it worked.

Decompression error: ShortRead
error: script "process" was terminated by signal SIGSEGV (Address boundary error)
FrancoLab commented 8 months ago

Any suggestions on fixing this?

niieani commented 8 months ago

Could this be a duplicate of https://github.com/oven-sh/bun/issues/8017?

argosphil commented 8 months ago

Does this still happen with 1.0.27?

nerkn commented 8 months ago

Serving static image was terminated by signal SIGSEGV (Address boundary error) in 1.0.25 but working errorlessly in 1.0.27 fyi

argosphil commented 8 months ago

I suspect this was a duplicate of either #8017 or #8687, so I'd optimistically close the issue and reopen if I'm wrong.

Andndre commented 7 months ago

In my case (v1.0.27) it crashes after sending the image successfully, image image I am using Elysia latest (tested without and with @elysiajs/static plugin)

Andndre commented 7 months ago

My bad, upgrading to v1.0.29 seems to have fixed the issue!

In my case (v1.0.27) it crashes after sending the image successfully

ricardojmendez commented 7 months ago

I am getting what seems to be a related issue with v1.0.30 (still pursuing it, as it happens when I use a third-party library that relies on streams). 1.0.18 is the last version I get it working with.

Another user had reported similar behavior on #8017, which is already closed.

Any other pointers as to how to solve or work around this?

Thanks!

(Update: this is definitely bun-related - moving purely to node everything works as expected)

KilianB commented 7 months ago

I believe the root casue is related with the newer issue here: https://github.com/oven-sh/bun/issues/8984 . We decided to toss elysia as it wasn't useable with this fix, so I have not been tracking these issues closely.

4F2E4A2E commented 6 months ago

I just tested this with the version oven/bun:1.0.35 (arm) while building nuxt3.

maxflex commented 6 months ago

Tried all versions from the comments above. latest, 1.0.29, 1.0.18 – none works.

image

Had to fallback to yarn :(

inromualdo commented 6 months ago

I just tested this with oven/bun:1.1.3 and it seems to have fixed the issue.

ricardojmendez commented 6 months ago

I just tested this with oven/bun:1.1.3 and it seems to have fixed the issue.

Confirmed with 1.1.2 - it works for me both on macOS and Ubuntu.

Jarred-Sumner commented 6 months ago

I believe @cirospaciari fixed this in Bun v1.1

If you run into this again in the future, please leave a comment

roonie007 commented 6 months ago

EDIT: looks like it's related to docker, when I simply run bun run dev on the terminal without using docker environment everything works fine.

@Jarred-Sumner Same problem with Sveltekit SSR mode, running this command bun run dev using Docker oven/bun:1.1-alpine

bun script "dev" was terminated by signal SIGSEGV ( Address boundary error )

image

The docker compose:


version: '3.8'
services:
  db:
    image: bitnami/postgresql:latest
    container_name: db-${APP_PROJECT}-${APP_VERSION}
    network_mode: host
    volumes:
      - db_data:/bitnami/postgresql
    expose:
      - 5432
    environment:
      - ALLOW_EMPTY_PASSWORD=true
      - POSTGRESQL_USERNAME=postgres
      - POSTGRESQL_PASSWORD=postgres
    stop_grace_period: 1s
    tty: true

  app:
    image: oven/bun:1.1-alpine
    container_name: app-${APP_PROJECT}-${APP_VERSION}
    network_mode: host
    restart: always
    depends_on:
      - db
    expose:
      - ${APP_PORT}
    working_dir: /usr/src/app
    volumes:
      - .:/usr/src/app
    env_file:
      - .env
      - .env.development
    command: ['bun', 'run', 'dev']
    stop_grace_period: 1s
    tty: true

volumes:
  db_data:

I use WSL 2 under Windows and here are some informations about my system:

System:
  OS: Linux 5.15 Ubuntu 22.04.4 LTS 22.04.4 LTS (Jammy Jellyfish)
  CPU: (16) x64 12th Gen Intel(R) Core(TM) i5-12600K
  Memory: 22.65 GB / 27.30 GB
  Container: Yes
  Shell: 5.1.16 - /bin/bash
Binaries:
  Node: 21.7.2 - ~/.nvm/versions/node/v21.7.2/bin/node
  Yarn: 1.22.19 - /usr/bin/yarn
  npm: 10.5.0 - ~/.nvm/versions/node/v21.7.2/bin/npm
  pnpm: 8.15.4 - ~/.local/share/pnpm/pnpm
  bun: 1.1.1 - ~/.bun/bin/bun
roonie007 commented 6 months ago

For those looking for a solution, prisma was actually the problem, I was able to make it work by replacing binaryTargets and using engineType instead, as demonstrated below.

Before ( Not working )

generator client {
  provider      = "prisma-client-js"
  binaryTargets = "linux-musl-openssl-3.0.x"
}

After ( Working 🎉 )

generator client {
  provider   = "prisma-client-js"
  engineType = "binary"
}