These errors are fatal and loud for a reason. EBADF implies that the file descriptor we passed to close is not valid any longer. That means someone else closed a file descriptor that NIO believes it owns. This must always be immediately fatal, as it's impossible to recover from: the program is in a non-deterministic state.
In your case, are you handling file descriptors anywhere? Are you calling close on any, either directly or through Foundation's FileHandle or Pipe?
I'm just running the built in examples in the Swift NIO SSH repo (NIOSSHServer and NIOSSHClient). So that would mean the bug is somewhere in there. Maybe I should create an issue there in GitHub?
Yeah, that looks like a bug. I think fixing it should be as straightforward as calling dup on the two file descriptors here before we pass them to the withPipes call. Want to try that and see if it fixes your issue?
I got it working! Swift NIO SSH is a lot easier to use than I initially expected. Thank you for the great work on this library. Making something as complicated as SSH easy to use is definitely a great achievement.
(ICYMI: the GitHub link in the original post points to the result)