microsoft / go-winio

Win32 IO-related utilities for Go
MIT License
950 stars 182 forks source link

Support for reconnecting to an existing pipe #306

Open endocrimes opened 10 months ago

endocrimes commented 10 months ago

It is fairly common that software will create pipes and then need to re-connect to them later (an example being when using a fifo for streaming logs between processes, and wanting the listener to be able to re-listen in case of a crash or upgrade).

The Pipe API in go-winio unfortunately doesn't support this - as the ListenPipe function will attempt to create the FIFO - and error when it already exists.

I ended up forking go-winio to add a hacky function for this in 2019 (https://github.com/microsoft/go-winio/compare/main...endocrimes:go-winio:dani/safe-relisten#diff-c9a2c1c22d0d0cb9afa231de2930c35096c8cda653a3d6fc94e159bfdcd71b7f) that has been in production use in Nomad since then (https://github.com/hashicorp/nomad/pull/5864/) - but due to my lack of deep knowledge of Windows API never opened a PR here at the time without knowing how stable it would be.

Today, I find myself needing to use my fork in a different project, and so now I'd like to try and land this upstream 😅

(I also noticed that someone actually opened a PR with those changes in 2020, but nobody ever got around to reviewing them https://github.com/microsoft/go-winio/pull/170 - I'm happy to open a new PR if this is something that folks would like to add).