oven-sh / bun

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

Process is not terminated automatically #13887

Open OlegGulevskyy opened 2 months ago

OlegGulevskyy commented 2 months ago

What version of Bun is running?

1.1.27

What platform is your computer?

Darwin 23.6.0 arm64 arm

What steps can reproduce the bug?

I run a small script to read values from Firebase using Bun. When the value is read I expect the process to be terminated but instead - it hangs without any errors or any further status updates. I need manually to Ctrl + C the running process to get out of it. The logic of reading the values are completed correctly, so no issues on that side - just once my script has run, I expect it to exit the process.

Initially reported in Discord here.

Here is a quick reproduction steps.

  1. Create a file main.ts with following content
    
    import firebase from 'firebase-admin';
    import { applicationDefault } from 'firebase-admin/app';
    // Set to your Firebase URL
    const FIREBASE_URL = process.env.FIREBASE_URL;

export const firebaseApp = firebase.initializeApp({ // Use default gcloud currently set authentication // Probs irrelevant to the actual Bun issue // Just make sure you can authenticate to a Firebase credential: applicationDefault(), databaseURL: FIREBASE_URL, });

// Set to whatever path you need to access const TARGET_FIREBASE_PATH = 'users/1';

const run = async () => { const value = await firebaseApp .database() .ref(TARGET_FIREBASE_PATH) // Might be the issue somewhere here, how this once is working .once('value');

const val = value.val(); if (val === null) { console.error('No value found. Exiting...'); process.exit(0); // This is the only way to exit the process }

console.log(val); // Process is not exiting here, terminal just hangs around };

await run();



### What is the expected behavior?

Once the script has run, I'd expect it to exit by itself ?

### What do you see instead?

_No response_

### Additional information

_No response_
aexvir commented 1 month ago

also hitting this issue, it was a pain in the ass to debug what was going on in the end I ended up running the script with deno just to rule out that it was some kind of issue with the firebase package itself and with deno it works as expected, didn't try node because everything is typescript and didn't feel like spending the time making it work