From a6c3e96f7be5039c75e3db4e5a4c7977acbf3bc1 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Wed, 28 Jan 2026 14:41:14 -0800 Subject: [PATCH] s3tables: fix double-write issue in handleListTables Remove premature HTTP error writes from within WithFilerClient closure to prevent duplicate status code responses. Error handling is now consistently performed at the top level using isAuthError. --- weed/s3api/s3tables/handler_table.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/weed/s3api/s3tables/handler_table.go b/weed/s3api/s3tables/handler_table.go index 9e592b15a..8cea2d871 100644 --- a/weed/s3api/s3tables/handler_table.go +++ b/weed/s3api/s3tables/handler_table.go @@ -309,7 +309,6 @@ func (h *S3TablesHandler) handleListTables(w http.ResponseWriter, r *http.Reques return err } if accountID := h.getAccountID(r); accountID != nsMeta.OwnerAccountID { - h.writeError(w, http.StatusNotFound, ErrCodeNoSuchNamespace, "namespace not found") return ErrAccessDenied } @@ -326,7 +325,6 @@ func (h *S3TablesHandler) handleListTables(w http.ResponseWriter, r *http.Reques return err } if accountID := h.getAccountID(r); accountID != bucketMeta.OwnerAccountID { - h.writeError(w, http.StatusNotFound, ErrCodeNoSuchBucket, "bucket not found") return ErrAccessDenied } @@ -340,15 +338,12 @@ func (h *S3TablesHandler) handleListTables(w http.ResponseWriter, r *http.Reques // If the bucket or namespace directory is not found, return an empty result tables = []TableSummary{} paginationToken = "" + } else if isAuthError(err) { + h.writeError(w, http.StatusForbidden, ErrCodeAccessDenied, "Access Denied") } else { - var authErr *AuthError - if errors.As(err, &authErr) { - h.writeError(w, http.StatusForbidden, ErrCodeAccessDenied, err.Error()) - } else { - h.writeError(w, http.StatusInternalServerError, ErrCodeInternalError, fmt.Sprintf("failed to list tables: %v", err)) - } - return err + h.writeError(w, http.StatusInternalServerError, ErrCodeInternalError, fmt.Sprintf("failed to list tables: %v", err)) } + return err } resp := &ListTablesResponse{