isaacs/st — pull request #15 by rvagg (2013-01-07 03:13:11+00:00)
Title: Introduced FDManager to manage fds per Mount instance

This is addressing a few issues surrounding the use of cached `fd`s. Partly to address the persistent `fd`-related problems I'm getting on both production and development servers using st but also because the multi-mount test is persistently failing for me (Linux) on the current master. I've also had at least one instance where st has switched the file(s) its serving mid-run, as if the fds are getting mixed up somewhere (I saw a CSS file suddenly start serving the contents of a JS file!).

The global `streaming` and `pendingClose` operate across all instances of `Mount` so while multi-mounts have different caches (for everything), they share the same `streaming` and `pendingClose` references which can cause some awkward interactions. So I've lifted these both into the `Mount` instance so they are no longer shared.

There's some tiny timing issues, but the biggest one is that the `streaming` list is only appended to after a `stat` call, which is `nextTick` at the latest separated from fetching the `fd` from the `fd` cache. It's easily possible to have a close happen between these two.

I've introduced an `FDManager` that takes care of all fd opens, closes and use-locks, in the end, state-tracking became messy enough to warrant just pulling it out to a separate container.