From c3b4e5568cbcc325d027c59ca67e64be3bb24024 Mon Sep 17 00:00:00 2001 From: robobun Date: Sun, 18 Jan 2026 13:19:30 -0800 Subject: [PATCH] fix(http): check socket state before operations in doRedirect (#26221) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary - Fix assertion failure when using HTTP proxy with redirects and socket closes during redirect processing - Add `isClosedOrHasError()` checks before `releaseSocket` and `closeSocket` in `doRedirect` Fixes #26220 ## Root Cause In `doRedirect` (`src/http.zig:786-797`), the code called `releaseSocket` or `closeSocket` without checking if the socket was already closed. When `onClose` is triggered while `is_redirect_pending` is true, it calls `doRedirect`, but the socket is already closed at that point, causing the assertion in `HTTPContext.zig:168` to fail: ```zig assert(!socket.isClosed()); // FAILS - socket IS closed ``` ## Fix Added `!socket.isClosedOrHasError()` checks before socket operations in `doRedirect`, matching the pattern already used at line 1790 in the same file. ## Test plan - [x] All existing proxy redirect tests pass (`bun bd test test/js/bun/http/proxy.test.ts`) - [x] Build completes successfully (`bun bd`) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Bot Co-authored-by: Claude Opus 4.5 --- src/http.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/http.zig b/src/http.zig index 512335d714..df00a8038c 100644 --- a/src/http.zig +++ b/src/http.zig @@ -783,7 +783,7 @@ pub fn doRedirect( NewHTTPContext(is_ssl).closeSocket(socket); } else { // we need to clean the client reference before closing the socket because we are going to reuse the same ref in a another request - if (this.isKeepAlivePossible()) { + if (this.isKeepAlivePossible() and !socket.isClosedOrHasError()) { log("Keep-Alive release in redirect", .{}); assert(this.connected_url.hostname.len > 0); ctx.releaseSocket(