jvilk / BrowserFS

BrowserFS is an in-browser filesystem that emulates the Node JS filesystem API and supports storing and retrieving files from various backends.
Other
3.07k stars 218 forks source link

Race condition with process.exit functions #28

Closed perimosocordiae closed 11 years ago

perimosocordiae commented 11 years ago

See commit b7d3d41f27d83a9ef755ba2d1ce982169564bb62.

Even with the hackfix, it's still possible to get errors on occasion.

perimosocordiae commented 11 years ago

This problem is even more manifest in the new indexedDB-based FS. Somewhere along the way during the loadFixtures call, the setImmediate wrapper isn't used and the test runner assumes everything is ready, when in fact no callback from either mkdir has been fired.

jvilk commented 11 years ago

My idea is to have a counter that's initialized to 0. We increment it by 1 when wrapCb is called (https://github.com/jvilk/BrowserFS/blob/master/src/core/node_fs.coffee#L5), and decrement it by 1 when the setImmediate portion of the wrapped cb is called. This should provide us with the semantics we want: The process has "exited" once all filesystem API calls have completed.

I tried implementing this locally, but it did not terminate. This means that we could have a silent bug where the callback isn't being triggered properly.