oven-sh / bun

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

Bun fails ~sometimes~ running shell command "patch" #15316

Open jpasquers opened 18 hours ago

jpasquers commented 18 hours ago

What version of Bun is running?

1.1.36

What platform is your computer?

Darwin 23.6.0 arm64 arm

What steps can reproduce the bug?

Setup Steps

  1. Make sure gpatch is installed (brew install gpatch) - version 2.7.6. (Can check patch --version to confirm)
  2. Within a fresh directory
  3. Run bun init
  4. Populate index.ts with this:
    
    import {$} from "bun";

try { await $patch '-p1' --no-backup-if-mismatch -d '.' < './fix.patch'; console.log("Succeeded :)"); } catch(e) { console.log("Failed :("); }

5. Create fix.patch and put this in it:

--- a/stuff.txt +++ b/stuff.txt @@ -1,7 +1,7 @@ Hello there general -Kenobi +Homie how art thou

6. Create stuff.txt and put this in it

Hello there general Kenobi how art thou


### Control Scenario - Bun patch works, and direct patch works

1. Run patch `-p1' --no-backup-if-mismatch -d '.' < './fix.patch`. This is the normal gpatch behavior
2. As a result you should see a success message and stuff.txt should have “Homie” instead of “Kenobi”, meaning the patch worked
3. undo the patch in stuff.txt so it says Kenobi again.
4. Run `bun run index.ts`
5. You should see another success and stuff.txt is again changed to “Homie”.
6. Undo the patch again

### Problem scenario - direct patch works, Bun command fails.

1. Make sure stuff.txt is in the original state, with Kenobi
2. Create an inner folder (I called mine src) and move stuff.txt into that folder.
3. Change fix.patch to point to the correct paths, aka:

--- a/src/stuff.txt +++ b/src/stuff.txt @@ -1,7 +1,7 @@ Hello there general -Kenobi +Homie how art thou


4. From the original directory (aka not src), run the patch command again, i.e.: patch `-p1' --no-backup-if-mismatch -d '.' < './fix.patch`
5. Confirm that this succeeded and still changed the values in stuff.txt from Kenobi to Homie, and then reset it back to Kenobi
6. Run `bun run index.ts` again. You should see a failure with: `/opt/homebrew/bin/patch: **** out of memory`

### What is the expected behavior?

Bun execution of gpatch should succeed in both cases, not produce an `out of memory` error.

### What do you see instead?

`/opt/homebrew/bin/patch: **** out of memory`

### Additional information

I understand this is a niche interaction of a particular shell command executed within Bun. But given the exact same scenario works with the direct command, I feel this could be a problem within Bun. I also wonder if the same bug causing this could be breaking other command executions