Open RobertoGeuke opened 4 months ago
Duplicate of https://github.com/oven-sh/bun/issues/11568
Can you provide some code for us to reproduce the issue? We know there's something going wrong while it's formatting the stack trace for an Error object. Don't know any more than that though.
Actually, this might've been fixed today. Can you try bun upgrade --canary
Tested it with the most recent canary version but still got the segfault after ~100 invocations of our script. Unfortunately I can't share our code, but basically our bundle.ts script receives an entry file and bundles this file together with all it's dependencies into a bundle.js
file. Non-js dependencies (images, fonts, etc.) will also be chased and compiled into usable assets.
My hypothesis is that something the segfault occurs when we generate a .js
script which can render static versions of our react pages. The script will be used as follows: bun bundle.js page-subscribe nl > built/page-subscribe.nl.html
. The TS code of this script looks kind-off like:
1 // Entry point when building static HTML (build time, using node).
1 /// <reference types="node" />
2 import {createElement} from 'react';
3 import {renderToString} from 'react-dom/server';
4
5 import {FrontPage} from 'FrontPage';
6 import {getPage} from 'index';
7
8 import type Country from 'Country';
9
10 const page = process.argv[2];
11 const country = process.argv[3];
12 const spinner = process.argv[4];
13
14 function isCountry(country: string): country is Country {
15 return country === 'nl' || country === 'be';
16 }
17 if (!isCountry(country)) {
18 throw new Error(`Invalid country: ${country}`);
19 }
20 const staticProps = {country, spinner: spinner || undefined};
21 // Once we have more complex staticProps than just country, consume from stdin:
22 // const stdin = readFileSync(0, 'utf-8')
23 // const props = JSON.parse(stdin)
24
25 let html = renderToString(createElement(FrontPage, {Page: getPage(page), staticProps}));
26 // Replace content within <style> tags with the HTML-unescaped version. a > b becomes a > b.
27 // Notice: we are intentionally checking for <style and not <style> because there's extra attributes in that tag.
28 html = html.replace(/<style[\s\S]+<\/style>/g, (match) =>
29 match
30 .replace(/>/g, '>')
31 .replace(/</g, '<')
32 .replace(/'/g, "'")
33 );
34 process.stdout.write('<!DOCTYPE html>');
35 process.stdout.write(html);
36 process.stdout.write(`<script>window.staticRender=${JSON.stringify({page, staticProps})};</script>`);
How can we reproduce the crash?
We sometimes get seg faults when we run our bundle script using bun. I reproduced this a few times by running 100 invocations of our script and it happens once in ~60 invocations. Reproduced the seg fault again to generate a core dump and included backtrace from this core dump in the relevant log output.
Good to note that our bundle.ts script uses worked threads to parallelize our bundling tasks.
Relevant log output
Stack Trace (bun.report)
Bun v1.1.12 (
43f0913
) on linux x86_64 [AutoCommand]Segmentation fault at address 0x00007058
ld-temp.o:0
:WTF::Unicode::convertReplacingInvalidSequences
??
JSObjectInlines.h:134
:JSC::JSValue JSC::JSObject::getIfPropertyExists<JSC::Identifier>
PropertyTable.h:0
:JSC::JSValue JSC::JSObject::getIfPropertyExists<JSC::Identifier>
Function.h:38
:Zig::GlobalObject::GlobalObject
ld-temp.o:0
:JSC::ErrorInstance::getOwnPropertySlot
ld-temp.o:0
:JSC::Heap::runEndPhase
ld-temp.o:0
:JSC::Heap::runNotRunningPhase
ld-temp.o:0
:JSC::Heap::finishChangingPhase
ld-temp.o:0
:WTF::AutomaticThread::~AutomaticThread