Force IPV4 on cygwin ssh-agent connections #1344
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
After upgrading to node18, our SSH connections from windows started failing and I determined that the failure was caused by git-for-windows' ssh-agent listening on the ipv4 loopback address while ssh2 was attempting to connect to the ipv6 loopback address and failing as a result.
The change in node18 that causes this bug is the following:
nodejs/node#39987
which causes node to resolve addresses in the order that windows provides them rather than forcing ipv4 addresses to come first. This causes node's net implementation to use the ipv6 loopback address by default instead of the ipv4 loopback address like previously.
The unix-socket-emulation layer behind cygwin/msys2/git-for-windows binds directly to the ipv4 loopback address and doesn't appear to be able to bind to an ipv6 address:
https://github.com/git-for-windows/msys2-runtime/blob/be826601df87b13be6038bb7e23a01d92be7ef07/winsup/cygwin/fhandler/socket_local.cc#L802
hence just forcing the ip instead of something more substantial.
We use a wrapper around ssh2 which doesn't handle this error as gracefully as modern versions of SSH2 which throw this error:
ssh2/lib/agent.js
Line 371 in 739a589
Our wrapper would instead just crash the node process which was much harder to track down.