Check if the file descriptor really exists

If one of the `IO.pipe` calls fail, then the subsequent file descriptors will not be allocated. We need to account for this failure mode in the `ensure` block; otherwise the real error will be masked by an "undefined method on Nil" exception.

/cc @rtomayko