Gin
One fix in gin-gonic/gin, maintained by gin-gonic.
Back to all open-source fixesAbout Gin
Gin is one of the most widely used HTTP web frameworks for Go. It provides a fast router, middleware support, request binding and validation, and a set of renderers for JSON, HTML, files, and streamed responses, and is used in production by a large number of Go services.
My work on it
My contribution to Gin is in its response rendering layer, focused on thread safety. I fixed a renderer that modified a headers map owned by the caller, which caused stale headers on later responses and data races under concurrent load. An earlier attempt to fix the same issue had been closed without landing.
Making streamed responses safe for shared header maps
The problem. When streaming a response from a reader, Gin wrote Content-Length into the extra-headers map the caller passed in. If that map was reused, later responses carried a stale Content-Length and clients received an empty body. If concurrent requests shared the map, the race detector flagged it and the runtime could crash with “concurrent map writes”.
The fix. Content-Length is now set directly on the response headers, so the caller’s map is only ever read. Header precedence is unchanged.
How I tested it. Added a test that checks the caller’s map is untouched and that reusing it doesn’t carry a stale header into the next response. It fails on the old code and passes with the fix.