bun icon indicating copy to clipboard operation
bun copied to clipboard

Segmentation fault SIGSEGV (Address boundary error) working with streams

Open KilianB opened this issue 4 months ago • 3 comments

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.

KilianB avatar Feb 09 '24 10:02 KilianB

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

Jarred-Sumner avatar Feb 09 '24 13:02 Jarred-Sumner

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.

KilianB avatar Feb 09 '24 13:02 KilianB

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)

niieani avatar Feb 10 '24 08:02 niieani

Any suggestions on fixing this?

FrancoLab avatar Feb 13 '24 06:02 FrancoLab

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

niieani avatar Feb 16 '24 07:02 niieani

Does this still happen with 1.0.27?

argosphil avatar Feb 17 '24 09:02 argosphil

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

nerkn avatar Feb 19 '24 01:02 nerkn

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

argosphil avatar Feb 19 '24 07:02 argosphil

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 avatar Feb 29 '24 00:02 Andndre

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

Andndre avatar Feb 29 '24 01:02 Andndre

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)

ricardojmendez avatar Mar 13 '24 09:03 ricardojmendez

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.

KilianB avatar Mar 13 '24 12:03 KilianB

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

4F2E4A2E avatar Mar 26 '24 22:03 4F2E4A2E

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

image

Had to fallback to yarn :(

maxflex avatar Apr 03 '24 12:04 maxflex

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

inromualdo avatar Apr 10 '24 06:04 inromualdo

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.

ricardojmendez avatar Apr 10 '24 06:04 ricardojmendez

I believe @cirospaciari fixed this in Bun v1.1

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

Jarred-Sumner avatar Apr 10 '24 07:04 Jarred-Sumner

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 avatar Apr 11 '24 02:04 roonie007

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"
}

roonie007 avatar Apr 18 '24 07:04 roonie007