Fixes #4387. The PR is against master but it probably should go into v0.8.
Minor nit about setting this.fd = null, but otherwise LGTM. (If there's some reason not to do that, then that's probably fine, too; it's an edge case.)
fs: fix ReadStream fd leak
Close the file descriptor when a read operation fails.
fs: fix WriteStream fd leak
Close the file descriptor when a write operation fails.
Landed in v0.8 in 6e97b2c and d65832c.
@bnoordhuis Can you review 4791c32 and let me know if you think it's still a valid test for this issue?
The timing of events in fd streams is a bit different in streams2, so the test needed a bit of refactoring.