oven-sh / bun

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

Segmentation fault when using AWS CDK lib #11002

Closed acollins1991 closed 4 months ago

acollins1991 commented 4 months ago

How can we reproduce the crash?

Create a Bun runtime project with the 'JavaScript/TypeScript code that reproduces the crash' code, updating PATH TO FILE to a file to build.

To get the exact scenario this script should be run using 'bun test' inside a monorepo setup, but have not tested if this is necessary.

The failure seems to occur when this line is run;

const code = props.code.bind(this);

in node_modules/aws-cdk-lib/aws-lambda/lib/function.js (https://github.com/aws/aws-cdk/blob/c1a3075c697b9673980315cab21cba0eea18782c/packages/aws-cdk-lib/aws-lambda/lib/function.ts#L912)

JavaScript/TypeScript code that reproduces the crash?

import * as cdk from "aws-cdk-lib";
import type { IFunction } from "aws-cdk-lib/aws-lambda";
import * as lambda from 'aws-cdk-lib/aws-lambda';
import { Construct } from "constructs";
import path from "path"

const bunFunction = await Bun.build({
  entrypoints: [PATH TO FILE],
  outdir: 'dist',
  target: 'bun',
  minify: true,
  external: ["*"]
})

export class BunCdkStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const fn: IFunction = new lambda.Function(this, 'HelloHandler', {
      code: lambda.Code.fromAsset(path.dirname(bunFunction.outputs[0].path)),
      handler: 'index.handler',
      runtime: lambda.Runtime.PROVIDED_AL2,
    });
  }
}

Relevant log output

root@342491c2aaba:/workspaces/distributed-rendering-businesses-monorepo# bun test packages/cdk
bun test v1.1.8 (89d25807)

packages/cdk/__tests__/cdk.spec.ts:
starting
============================================================
Bun v1.1.8 (89d25807) Linux x64 (baseline)
Args: "bun", "test", "packages/cdk"
Features: jsc bunfig dotenv(2) external tsconfig 
Builtins: "node:buffer" "node:constants" "node:crypto" "node:fs" "node:os" "node:path" "node:stream" "node:string_decoder" "node:util" "node:util/types" 
Elapsed: 938ms | User: 556ms | Sys: 381ms
RSS: 2.13GB | Peak: 1.07GB | Commit: 2.13GB | Faults: 2

panic(main thread): Segmentation fault at address 0x0

Stack Trace (bun.report)

Bun v1.1.8 (89d2580) on linux x86_64_baseline [TestCommand]

Segmentation fault at address 0x00000000

Jarred-Sumner commented 4 months ago

Duplicate of https://github.com/oven-sh/bun/issues/5398

Jarred-Sumner commented 4 months ago

Closing as duplicate