gin-contrib / timeout

Timeout middleware for Gin
MIT License
185 stars 38 forks source link

[Bug] panic: http: wrote more than the declared Content-Length #1

Closed hantmac closed 3 years ago

hantmac commented 4 years ago

After timeout, the original goroutine still is running, and will cause panic finally.

The panic info is:

[GIN-debug] [WARNING] Headers were already written. Wanted to override status code 408 with 200
panic: http: wrote more than the declared Content-Length

image

fnsne commented 4 years ago

I found the solution in the other timeout implement. https://github.com/vearne/gin-timeout By injecting other Writer to the wrapped function, and using the select case to chose what to write.

hantmac commented 4 years ago

I found the solution in the other timeout implement. https://github.com/vearne/gin-timeout By injecting other Writer to the wrapped function, and using the select case to chose what to write.

I saw it, but I think his code is so complicated 🤔.

appleboy commented 4 years ago

Let me think about how to resolve the issue.

ghost commented 3 years ago

Any progress on fixing this?

ghost commented 3 years ago

Found a workaround until this is fixed.

Just check if the context is aborted anywhere else that attempts to write. Not ideal, but it worked for me.

justlazydog commented 3 years ago

Is it possible that gin's repo provides a func to copy or clone c.Writer.

appleboy commented 3 years ago

Fix by #2