Skip to content

Error logs coming for http: superfluous response.WriteHeader call when using otelhttp handler #6053

@vipul-rawat

Description

@vipul-rawat

Description

A clear and concise description of what the bug is.

In the latest release the call to request.Write() is setting the response headers to http.StatusOK without checking if the WriteHeader is already called, this is causing issues when trying to set Status Codes and then trying to Write to the response.

Environment

  • OS: darwin
  • Architecture: arm64
  • Go Version: go 1.22
  • otelhttp version: v0.54.0

Steps To Reproduce

  1. Using this code ...
package main

import (
	"fmt"

	"gofr.dev/pkg/gofr"
)

func main() {
	a := gofr.New()

	a.GET("/hello", HelloHandler)

	a.Run()
}

func HelloHandler(c *gofr.Context) (interface{}, error) {
	name := c.Param("name")
	if name == "" {
		c.Log("Name came empty")
		name = "World"
	}

	return fmt.Sprintf("Hello %s!", name), nil
}

  1. Run ...
go run main.go

curl --location 'localhost:8000/hello'
  1. See error ...
    image

Expected behavior

The Write() call should check if the wroteHeader is true before calling WriteHeader()

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions