Repository navigation
Check SO_ERROR when a connect() retry answers EISCONN on macOS - #1401
Merged
Merged
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
ABI compatibility check✅
|
redisCheckConnectDone() learns the result of a non-blocking connect by calling connect() again, and maps EISCONN to "connected". Since macOS 26.7 / 15.8.1 (and on macOS 27) the retry answers EISCONN for a refused connect too, while SO_ERROR still holds ECONNREFUSED. hiredis then treats the dead socket as connected, fails setting TCP_NODELAY with EINVAL, closes the fd and reports "setsockopt(TCP_NODELAY): Invalid argument" instead of "Connection refused". On macOS, read SO_ERROR on EISCONN and fail with the pending error if there is one. Other platforms are left as they are: no other kernel is known to do this (FreeBSD still reports the refusal on the retry), and on Linux SO_ERROR may hold a queued error on a socket that is connected and usable. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
uglide
force-pushed
the
im/fix-eisconn-refused-connect
branch
from
November 18, 2026 18:04
b2cbeaa to
7ff0002
Compare
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.
Problem
redisCheckConnectDone()finds out how a non-blocking connect ended by callingconnect()again, and mapsEISCONNto "connected". Since macOS 26.7 / 15.8.1 (and on macOS 27), that retry returnsEISCONNfor a refused connect too, whileSO_ERRORstill holdsECONNREFUSED:(macOS 26.7.2 25G332 and 15.8.2 24H232 on the GitHub runners. On 26.6.2 25G83 the retry still returned
ECONNREFUSED.)So hiredis treats the dead socket as connected. Setting
TCP_NODELAYthen fails withEINVAL,redisSetTcpNoDelay()closes the fd, and the caller seessetsockopt(TCP_NODELAY): Invalid argumentinstead ofConnection refused. This is whytest.c#71 and #72 fail on the current macOS runner (e.g. in #1400). The async API takes the same path: the connect callback runs after the fd has been closed and while the adapter still watches that fd number, which is how we ran into #1399.Other projects hit the same change and fixed it the same way, by reading
SO_ERROR:Socket#connecton Unix crystal-lang/crystal#17436Fix
On macOS, when the retry returns
EISCONN, readSO_ERROR. If an error is pending, seterrnoto it and returnREDIS_ERR. Both callers (redisContextWaitReady()and__redisAsyncHandleConnect()) then report it throughredisCheckSocketError(), which falls back to the savederrnoonceSO_ERRORhas been read, so the message isConnection refusedagain.The check applies only under
__APPLE__:SO_ERRORcan hold a queuedIP_RECVERRerror on a socket that is connected and usable (the "Connection with a queued error remains usable" test), so reading it there would be wrong.Testing
makewith-Werroron Linux. The macOS branch also compiles cleanly with-D__APPLE__.test.cA GLib adaptor #71 / Fix self-test of connect error on Linux; merge duplicated string (DRY) #72, which fail on the macOS 26.7.2 runner without this change. This PR's macOS job is the check.🤖 Generated with Claude Code
Note
Low Risk
Small, platform-guarded change to connect completion handling; main risk is mis-detecting failures on Apple builds, with Linux paths untouched.
Overview
Fixes a macOS-specific non-blocking connect regression where retrying
connect()after a refused connection returnsEISCONNwhileSO_ERRORstill holdsECONNREFUSED. Hiredis previously treated that as success, which could close the socket on laterTCP_NODELAYand surface misleading errors instead of "Connection refused".On
EISCONNonly when__APPLE__is defined,redisCheckConnectDone()now readsSO_ERROR; if a pending error is set, it propagates viaerrnoand returnsREDIS_ERRinstead of marking the connection complete. Linux behavior is unchanged (no extraSO_ERRORread onEISCONNthere).Reviewed by Cursor Bugbot for commit 7ff0002. Bugbot is set up for automated code reviews on this repo. Configure here.