Force SOCK_STREAM in getAddrInfo hints to fix macOS/BSD connect bug#29
Merged
Conversation
Socket.defaultHints leaves addrSocketType as NoSocketType, so getaddrinfo() is free to return entries in any order for the requested host/port. On macOS this can return a SOCK_DGRAM (UDP) entry before the SOCK_STREAM (TCP) one for the same loopback host/port; internalConnectOrCancel takes the first result unconditionally, so hpgsql ends up opening a UDP socket to Postgres. connect()/send() on that UDP socket "succeed" (UDP has no handshake), so the startup message appears to be sent successfully. The failure only surfaces on the first recv(), as ECONNREFUSED from an ICMP port-unreachable reply, since nothing is listening on that UDP port. Postgres never sees any connection attempt when this happens. Explicitly requesting addrSocketType = Stream removes the UDP entries from getAddrInfo's results.
Owner
|
Thank you very much for creating the ticket and even a PR. The PR's summary is well written, and the change looks good and passes CI and in my Linux computer. Are you happy with the PR in its current state? I can approve and merge if you are. Also, can you use hpgsql from |
Contributor
Author
|
Hi Marcelo,
Thanks. You can go ahead and merge it. I'm building with a local copy of
the repo, but I think that a release is a good idea and could potentially
save some time for other users.
Regards,
Kamil
…On Thu, Jul 2, 2026 at 9:57 PM Marcelo Zabani ***@***.***> wrote:
*mzabani* left a comment (mzabani/hpgsql#29)
<#29 (comment)>
Thank you very much for creating the ticket and even a PR. The PR's
summary is well written, and the change looks good and passes CI and in my
Linux computer.
Are you happy with the PR in its current state? I can approve and merge if
you are.
Also, can you use hpgsql from master, or does it help if I release a new
version in hackage? I can try to make a release tomorrow or next week if
one is needed.
—
Reply to this email directly, view it on GitHub
<#29?email_source=notifications&email_token=AAAFW5U2XMOHNCBN73PFACD5C25CVA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTIOBWHE4TKMZZGI22M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2KYZTPN52GK4S7MNWGSY3L#issuecomment-4869953925>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAFW5S6X4IL6NBXXGL6PYL5C25CVAVCNFSNUABGKJSXA33TNF2G64TZHMYTCNZZGE2TEOJXGQ5US43TOVSTWNBXHE3TKNRTGY2DNILWAI>
.
Triage notifications, keep track of coding agent tasks and review pull
requests on the go with GitHub Mobile for iOS
<https://github.com/notifications/mobile/ios/AAAFW5SOYLPIQN6VNDUCCZ35C25CVA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTIOBWHE4TKMZZGI22M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2KUZTPN52GK4S7NFXXG>
and Android
<https://github.com/notifications/mobile/android/AAAFW5QWNCUFJRUPEOLXJLT5C25CVA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTIOBWHE4TKMZZGI22M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2K4ZTPN52GK4S7MFXGI4TPNFSA>.
Download it today!
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Owner
|
Good point, I will try to release a new version as soon as I can. Thank you very much for your contribution, and feel free to keep them coming. |
Owner
|
New version with this fix just published to Hackage. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Socket.defaultHints leaves addrSocketType as NoSocketType, so getaddrinfo() is free to return entries in any order for the requested host/port. On macOS this can return a SOCK_DGRAM (UDP) entry before the SOCK_STREAM (TCP) one for the same loopback host/port; internalConnectOrCancel takes the first result unconditionally, so hpgsql ends up opening a UDP socket to Postgres.
connect()/send() on that UDP socket "succeed" (UDP has no handshake), so the startup message appears to be sent successfully. The failure only surfaces on the first recv(), as ECONNREFUSED from an ICMP port-unreachable reply, since nothing is listening on that UDP port. Postgres never sees any connection attempt when this happens.
Explicitly requesting addrSocketType = Stream removes the UDP entries from getAddrInfo's results.
This fixes issue #28