Skip to content

[bug] RunSSEHandler causes "superfluous response.WriteHeader" on errors #510

@innomon

Description

@innomon

Description

The RunSSEHandler in server/adkrest/controllers/runtime.go explicitly calls rw.WriteHeader(http.StatusOK) before streaming events. When an error occurs later and the handler returns an error, the NewErrorHandler wrapper attempts to call http.Error() which internally calls WriteHeader() again, causing:

http: superfluous response.WriteHeader call from google.golang.org/adk/server/adkrest/internal/routers.(*RuntimeAPIRouter).Routes.NewErrorHandler.func2 (handlers.go:48)

Root Cause

In runtime.go line 108:

rw.WriteHeader(http.StatusOK)  // Called here first
for event, err := range resp {
    if err != nil {
        // Error written, handler returns...
    }
}

Then in handlers.go line 46-48:

if statusErr, ok := err.(statusError); ok {
    http.Error(w, statusErr.Error(), statusErr.Status())  // Tries to WriteHeader again
}

Suggested Fix

Remove the explicit rw.WriteHeader(http.StatusOK) call. Go's HTTP server will automatically send 200 OK on the first write.

// BEFORE (runtime.go line 108):
rw.WriteHeader(http.StatusOK)

// AFTER:
// (remove this line - first fmt.Fprintf will implicitly set 200 OK)

Environment

  • ADK version: v0.2.0
  • Go version: 1.24

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions