Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bun crashed. #18105

Open
maxvonhippel opened this issue Mar 12, 2025 · 1 comment
Open

bun crashed. #18105

maxvonhippel opened this issue Mar 12, 2025 · 1 comment
Labels
crash An issue that could cause a crash macOS An issue that occurs on macOS

Comments

@maxvonhippel
Copy link

maxvonhippel commented Mar 12, 2025

How can we reproduce the crash?

I did this a gajillion times in a row on different things

// Helper function to check if a module can be imported - synchronous version
function canImportModule(moduleName: string): boolean {
    // Add debug logging
    console.log('Resolving:', {
        moduleName,
        cwd: process.cwd(),
    });

    // Check cache first to ensure consistent results
    if (moduleCache.has(moduleName)) {
        return moduleCache.get(moduleName)!;
    }
    
    // Prevent infinite recursion
    if (processingModules.has(moduleName)) {
        return true;
    }
    processingModules.add(moduleName);

    // Trust built-in modules (both Node.js and Bun)
    const bareModuleName = moduleName.replace(/^(node:|bun:)/, '');
    if (builtinModules.includes(bareModuleName)) {
        processingModules.delete(moduleName);
        moduleCache.set(moduleName, true);
        return true;
    }

    try {
        // First, try to resolve as a package
        const resolvedPath = require.resolve(moduleName, {
            paths: [process.cwd()]
        });
        
        // If it resolves to node_modules, trust it completely
        if (resolvedPath.includes('node_modules')) {
            console.log('Resolved to node_modules:', resolvedPath);
            processingModules.delete(moduleName);
            moduleCache.set(moduleName, true);
            return true;
        }

        // For non-node_modules resolutions, continue with validation
        const imports = extractImports(resolvedPath);
        const allImportsValid = imports.every(imp => {
            // Resolve relative imports relative to the current file
            if (imp.startsWith('.')) {
                const dir = path.dirname(resolvedPath);
                return canImportModule(path.resolve(dir, imp));
            }
            return canImportModule(imp);
        });

        processingModules.delete(moduleName);
        moduleCache.set(moduleName, allImportsValid);
        return allImportsValid;

    } catch (error) {
        // If resolution fails, it's not a valid import
        processingModules.delete(moduleName);
        moduleCache.set(moduleName, false);
        return false;
    }
}

and it seg faulted

Relevant log output

Stack Trace (bun.report)

Bun v1.1.30 (7996d06) on macos aarch64 [TestCommand]

Segmentation fault at address 0x00000008

  • 1 unknown/js code
  • ??
  • ??
  • ??
  • ??
  • ??
  • ??
  • ??
  • ??
  • ??

Features: bunfig, jsc, transpiler_cache, tsconfig

Sentry Issue: BUN-22K

@maxvonhippel maxvonhippel added the crash An issue that could cause a crash label Mar 12, 2025
@github-actions github-actions bot added the macOS An issue that occurs on macOS label Mar 12, 2025
Copy link
Contributor

@maxvonhippel, the latest version of Bun is v1.2.5, but this crash was reported on Bun v1.1.30.

Are you able to reproduce this crash on the latest version of Bun?

bun upgrade

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash An issue that could cause a crash macOS An issue that occurs on macOS
Projects
None yet
Development

No branches or pull requests

1 participant