gin-contrib / gin-contrib/timeout
Timeout behavior regression in v1.2.1
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 237
- Forks
- 42
- Avg merge
- 3d 3h
- Merged PRs (30d)
- 2
Description
Summary
There appears to be a regression in github.com/gin-contrib/timeout starting from v1.2.1.
The timeout middleware does not terminate the request at the configured timeout duration and instead waits until the handler completes.
Environment
- github.com/gin-contrib/timeout: v1.2.1
- github.com/gin-gonic/gin: v1.12.0
Reproduction
- Use the following test code
package main
import (
"log"
"net/http"
"time"
"github.com/gin-contrib/timeout"
"github.com/gin-gonic/gin"
)
func testResponse(c *gin.Context) {
c.String(http.StatusRequestTimeout, "timeout")
}
func timeoutMiddleware() gin.HandlerFunc {
return timeout.New(
timeout.WithTimeout(time.Second),
timeout.WithResponse(testResponse),
)
}
func main() {
r := gin.New()
r.Use(timeoutMiddleware())
r.GET("/slow", func(c *gin.Context) {
time.Sleep(5 * time.Second)
c.Status(http.StatusOK)
})
if err := r.Run(":8080"); err != nil {
log.Fatal(err)
}
}
- Run the server
$ go run main.go
- Call the endpoint
$ curl http://localhost:8080/slow -w "%{time_total} sec\n"
Results
Using gin-contrib/timeout v1.2.1:
5.001918 sec
Using gin-contrib/timeout v1.2.0:
1.001925 sec
Expected Behavior
When a timeout of 1 second is configured, the request should be terminated after ~1 second, and the timeout response should be returned.
Actual Behavior
- With v1.2.1, the request completes after ~5 seconds (the handler duration), not respecting the timeout.
- With v1.2.0, the timeout works correctly and returns after ~1 second.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the timeout middleware behavior in github.com/gin-contrib/timeout v1.2.1 and compare it with v1.2.0. Run the provided Go reproduction with Gin v1.12.0; done means the /slow request returns the timeout response after about one second instead of waiting five seconds.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100