oven-sh / bun

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

bun crashed "Segmentation fault" #11944

Closed scffs closed 1 month ago

scffs commented 3 months ago

How can we reproduce the crash?

I wrote a simple code that only make requests to server in a while. It is possible that the crash is in PC lock mode (Control-Command-Q)

Relevant log output

Bun v1.1.13 (bd6a6051) macOS Silicon
Args: "bun" "run" "--hot" "src/main.js"
Features: jsc Bun.stdin(2) fetch(9964) transpiler_cache(8) tsconfig
Builtins: "bun:main" "node:assert" "node:buffer" "node:crypto" "node:dns" "node:events" "node:fs" "node:fs/promises" "node:http" "node:net" "node:os" "node:process" "node:stream" "node:string_decoder" "node:timers" "node:tls" "node:tty" "node:url" "node:util" "node:util/types" "node:zlib"
Elapsed: 7393199ms | User: 94868ms | Sys: 32311ms
RSS: 0.25GB | Peak: 0.27GB | Commit: 1.07GB | Faults: 1753

panic: Segmentation fault at address 0x48C00F23C80
oh no: Bun has crashed. This indicates a bug in Bun, not your code.

Stack Trace (bun.report)

Bun v1.1.13 (bd6a605) on macos aarch64 [RunCommand]

Segmentation fault at address 0x48C00F23C80

in the 1.1.12 version of bun this code works fine (all day without crashing)

Jarred-Sumner commented 3 months ago

Any chance you could provide some code for us to reproduce the issue? The crash is saying that it is something to do with the HTTP client. But it's hard to assess further than that.

scffs commented 3 months ago

Any chance you could provide some code for us to reproduce the issue? The crash is saying that it is something to do with the HTTP client. But it's hard to assess further than that.

yes sure

import { connect } from 'mongoose'

const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms))

const connectToDatabase = async () => {
  try {
    await connect('mongodb://localhost:27017/test')
  } catch (error) {
    process.exit(1)
  }
}

export const getSmth = async () =>
  fetcher('https://jsonplaceholder.typicode.com/posts')

const fetcher = async (url, body = '{}') => {
  let items

  const response = await fetch(url, {
    method: 'POST',
    headers: {
      Authorization: '123',
      'Content-Type': 'application/json'
    },
    body
  }).catch((error) => {
    console.error(`Error (${new Date().toISOString()}): ${error}`)
  })

  try {
    const r = await response.json()

    // IDK why there is no return but it works
    if (response.status !== 200) {
      console.error(r)
    }

    console.log('r', r)

    items = r
  } catch (err) {
    return null
  }

  await delay(450)
  return items
}

// a simplified version of my code
async function main() {
  // could comment this I guess
  await connectToDatabase()

  // I'm getting some data to display it in the console
  const someData = await getSmth()

  while (true) {
    const newInterval = 1000

    try {
      await getSmth()
    } catch (error) {
      console.error(error)
    }

    // in my case, I get an array of some elements and in a loop I run a different query for each of these elements
    for (let i = 0; i < 10; i++) {
      await getSmth()
    }

    await getSmth()
    await delay(newInterval)
  }
}

main()
scffs commented 3 months ago

@Jarred-Sumner, hi again

According to my observations, the script really crashes after the screen is locked or during somehow

image

by the way, I have 2 identical scripts running (let's imagine that I have 2 identical projects in different folders and work independently of each other) and as a rule only 1 crashes

cirospaciari commented 2 months ago

Can you still reproduces it on v0.0.20? This looks like a issue that is already solved

scffs commented 2 months ago

Can you still reproduces it on v0.0.20? This looks like a issue that is already solved

I'll check this today

scffs commented 2 months ago

looks like fixed

but can you please provide any information? like PR that fixed this bug or whatever

@cirospaciari

scffs commented 2 months ago
image

I got this error again xd @cirospaciari

cirospaciari commented 2 months ago

We added some fixes into sockets, can you try bun upgrade --canary and check if is still happening?

scffs commented 1 month ago

fixed at 1.1.24