# Why rmSync froze our Electron main process

> rmSync on twenty Chromium profile folders stopped Mosaic for 0.70 s, and the API answered one request. A rename plus fs.promises.rm took 0.06 s.

Source: https://mosaicbrowser.com/blog/empty-trash-freeze

## Emptying the trash stopped the whole application

rmSync on twenty Chromium profile folders stopped Mosaic for 0.70 s, and the API answered one request. A rename plus fs.promises.rm took 0.06 s.

![0.70 s: One request answered while the trash emptied, beside a screenshot: the Mosaic trash: deleted profiles kept for 30 days, restorable one by one](https://mosaicbrowser.com/covers/empty-trash-freeze.webp)

`fs.rmSync` blocks the Electron main process for as long as it takes to unlink every file, and a Chromium profile folder has hundreds of them. Mosaic used it to empty the trash. On 29 September 2026 we measured twenty profiles taking 0.70 seconds, and in that time the local API answered one request. The app was not slow. It was stopped.

## "Deleting a bunch of things from trash almost crashed my PC"

That was the report. Nothing crashed, but from the outside a frozen main process and a crash look much the same: the window stops drawing, clicks queue up, and macOS starts offering to force-quit.

The code path was short. `purgeProfile` removed a profile's browser data with:

```
rmSync(dir, { recursive: true })

```

and `emptyTrash` called `purgeProfile` in a loop. A Chromium profile folder is not one file. On our machine they held between 488 and 849 entries and 16 to 53 MB each: caches, databases, journals, extension state. `rmSync` makes every one of those `unlink` calls on the thread that also runs the window, the IPC handlers and the REST server.

## How we measured rmSync blocking the main process

We seeded twenty profiles with a real profile's data, so each folder looked like one that had been used. Then we called `POST /trash/empty` against the running app while a second thread polled the API as fast as it could.

```
POST /trash/empty   0.70 s   API answered 1 request in that window

```

One answer in 0.70 seconds is the number that matters. A duration alone would have said the purge was a bit slow. The request count says nothing else in the process ran. A real trash holds a hundred-odd rows, not twenty, so in practice this was several seconds of a beachballed application.

We will not see this on our own machines unless we look for it. A developer testing the trash deletes three profiles that have never been opened, and each folder is a handful of files.

Mosaic is a desktop app

Email yourself the link and open it on your computer.

[How it works: Bulk actions](https://mosaicbrowser.com/features/bulk-actions)

## Two suspects that were innocent

Both of these looked like the cause, and each took a measurement to rule out.

1. **The store write.** Mosaic's state file is saved through a 150 ms debounce. The loop is synchronous, so the timer cannot fire inside it, and the whole purge writes the file once, at the end.
2. **The safety snapshot.** A purge takes a backup of the library first, and that is coalesced to one per 60 seconds. It copies the profiles' JSON, not their browser data, so it is small, and a purge of any size takes one.

Both were already correct. The time was all in `unlink`.

## A rename is one operation

Renaming a folder costs the same whether it holds one file or eight hundred. So the purge now does the part that has to happen at once, which is removing the index entry and the profile's own JSON, and then moves the data folder aside:

1. `purgeDataDir` renames the folder into `profile-data/.purging/`, under a fresh name, so two profiles purged in one burst cannot collide.
2. The recursive delete goes to `fs.promises.rm`, which runs on libuv's thread pool, off the main thread.
3. If the rename itself fails, it falls back to the old synchronous delete. A staging folder we cannot write to must not turn a purge into a no-op that leaves the data in place.
4. At startup, a sweep deletes anything left in `.purging`, because a rename that lands followed by a quit leaves a folder nothing points to.

Same twenty profiles, after:

```
POST /trash/empty   0.06 s   and the process answers during it

```

We also checked the bytes really went. All twenty folders were gone from disk, `.purging` was empty, and the data folder dropped from 1.1 GB to 649 MB. A purge that only looks fast because it stopped deleting would be the worse bug.

![The Mosaic trash, with Empty trash at the top right](https://mosaicbrowser.com/shots/trash.png)
*Empty trash now returns at once, and the files still go*

## The rule we wrote down

Synchronous filesystem work in the main process is a freeze whose length depends on someone else's data. The folder size is set by how much the person browsed, not by anything in our code. And when you test a destructive path, poll the process during it. A timer says the path was slow; the number of requests answered says whether it stopped.

Trashing a profile also closes its browser before anything is moved, which is its own story in [trashing a profile closes its browser](https://mosaicbrowser.com/blog/trash-closes-the-browser). Move to trash in the [bulk bar](https://mosaicbrowser.com/features/bulk-actions) deletes nothing; the files go when you press Delete on a row in the trash, press Empty trash, or the 30 days run out, and all three take the same rename-then-delete path. Over the [local REST API](https://mosaicbrowser.com/features/rest-api) it is `POST /trash/empty`, which refuses to run until the body says what to empty. The profiles, their trash and the staging folder all stay on your computer, as [local-first](https://mosaicbrowser.com/features/local-first) describes.

## Questions

### Does fs.rmSync block the Electron main process?

Yes. Every unlink it makes runs on the main process's own thread, so nothing else there runs until it returns: no IPC, no window events, no timers, no HTTP server. On a folder of hundreds of files that is a visible freeze.

### What did Mosaic replace rmSync with?

A rename of the profile's data folder into a staging folder, which is one filesystem operation whatever the folder holds, followed by fs.promises.rm, which runs the recursive delete on Node's thread pool.

### What happens if Mosaic quits halfway through emptying the trash?

The renamed folders wait in the staging folder, which nothing else reads. A sweep at the next start deletes whatever is there, in the background.

### Does emptying the trash really delete the files?

Yes. We checked all twenty test folders were gone from disk, the staging folder was empty, and the data folder went from 1.1 GB back to 649 MB.

## Related

[Trashing a profile closes its browser, at every door](https://mosaicbrowser.com/blog/trash-closes-the-browser): Delete a running profile in Mosaic and its browser closes first. If the browser will not close, the profile stays on the list, with its Stop button.

[Bulk edit browser profiles: start, tag, move and arrange](https://mosaicbrowser.com/features/bulk-actions): Bulk edit browser profiles in Mosaic: start, stop, edit, tag, move or re-proxy a selection together, arrange its windows, and type into all of them.

[Local first: your profiles stay on your computer](https://mosaicbrowser.com/features/local-first): Mosaic has no cloud copy of your profiles. Profiles, cookies and proxies stay on your computer, encrypted on disk, with app lock, daily backups and a trash.

[One Dock tile per window slot, and a banner we can't stop](https://mosaicbrowser.com/blog/dock-tile-per-slot): macOS gives one Dock tile per app identity, and greets each new one with a banner. We pool identities by open window: five, not one per profile.

[Anti-detect browser REST API: profiles from your scripts](https://mosaicbrowser.com/features/rest-api): Mosaic's anti-detect browser REST API runs on 127.0.0.1 with API keys. Create and start profiles, then attach Puppeteer or Playwright over CDP.



[Yearly discounts on anti-detect browsers, read in full](https://mosaicbrowser.com/blog/annual-discounts-anti-detect): At 40% off, a prepaid year costs what 7.2 months of monthly billing would. It is also a bet that the engine keeps up with Chrome for twelve months.



## Mosaic, on your own computer

The browser this blog is about: its own Chromium, fingerprints from real machines and a proxy IP per profile. Free covers 3 profiles with no card, and Pro is $25 a month for any number of them.

Mosaic is a desktop app

Email yourself the link and open it on your computer.
