Skip to content

libuv adapter: install hooks only once attach can no longer fail - #1400

Merged
uglide merged 1 commit into
masterfrom
im/fix-libuv-attach-failure
Nov 19, 2026
Merged

uglide merged 1 commit into
masterfrom
im/fix-libuv-attach-failure

Conversation

@uglide

@uglide uglide commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1399.

redisLibuvAttach() set the ac->ev.* hooks, ev.cleanup among them, before it allocated ev.data. If hi_malloc() or uv_poll_init_socket() then failed, it returned REDIS_ERR with ev.cleanup still installed and ev.data == NULL. The caller still owns the context and has to redisAsyncFree() it, which called redisLibuvCleanup(NULL) and dereferenced NULL at p->context = NULL.

This change sets the hooks only after the last point where attaching can fail, so a failed attach leaves the context as it found it. The other adapters either can't fail after setting their hooks or already set them last.

Testing

I ran the reproducer from #1399 with ASan and UBSan on Linux, libuv 1.52.1. It forces uv_poll_init_socket() to fail by having a second uv_poll_t already watch the fd.

  • before: SEGV in redisLibuvCleanup (adapters/libuv.h:133) ← redisAsyncFree
  • after: redisLibuvAttach -> REDIS_ERR, ev.data=(nil), ev.cleanup=(nil), then freed without crashing, with no sanitizer reports

I didn't add a regression test because test.c doesn't build against libuv today. If you'd like one, I can add a libuv-gated case.

🤖 Generated with Claude Code


Note

Low Risk
Local initialization order change in the libuv adapter; no behavior change on successful attach, only safer failure cleanup.

Overview
Fixes a crash when redisLibuvAttach() fails after partially wiring the async context.

redisLibuvAttach() now installs the ac->ev.* callbacks (including ev.cleanup) only after hi_malloc() and uv_poll_init_socket() succeed. Previously those hooks were set first, so a later failure returned REDIS_ERR with ev.cleanup set but ev.data still NULL; redisAsyncFree() then ran redisLibuvCleanup(NULL) and crashed. A failed attach now leaves the context unchanged, matching the other adapters’ pattern.

Reviewed by Cursor Bugbot for commit dc60712. Bugbot is set up for automated code reviews on this repo. Configure here.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-18T18:14:41.476568Z dc60712 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

ABI compatibility check

✅ libhiredis — compatible

No ABI changes detected.

✅ libhiredis_ssl — compatible

No ABI changes detected.

Baseline e90c24e2239395ea4eb4972cb14eb7a77a778d7b vs head dc607127ba6d8f4160210e8a43b9107ef50e1469. Apply the ignore-abi-check label to skip this check for an intentional, SONAME-bumped ABI break.

redisLibuvAttach() set ac->ev.cleanup before allocating ev.data. When
hi_malloc() or uv_poll_init_socket() then failed it returned REDIS_ERR
with the cleanup hook still installed and ev.data NULL, so the
redisAsyncFree() the caller must follow with called
redisLibuvCleanup(NULL) and dereferenced NULL.

Install the hooks after the last failure point, so a failed attach
leaves the context untouched.

Fixes #1399

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@uglide
uglide force-pushed the im/fix-libuv-attach-failure branch from d2a8ba4 to dc60712 Compare November 18, 2026 18:13
@uglide
uglide merged commit e751a28 into master Nov 19, 2026
27 checks passed
@uglide uglide added the bug label Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

libuv adapter: failed redisLibuvAttach leaves ev.cleanup set, so redisAsyncFree dereferences NULL

1 participant