Skip to content

fix: Remove deprecated http.CloseNotifier, use Request.Context().Done() in Stream#4587

Open
haesuo566 wants to merge 1 commit intogin-gonic:masterfrom
haesuo566:fix/Deprecated_CloseNotify
Open

fix: Remove deprecated http.CloseNotifier, use Request.Context().Done() in Stream#4587
haesuo566 wants to merge 1 commit intogin-gonic:masterfrom
haesuo566:fix/Deprecated_CloseNotify

Conversation

@haesuo566
Copy link
Copy Markdown
Contributor

@haesuo566 haesuo566 commented Mar 17, 2026

Summary

Fixes #4586

  • Remove http.CloseNotifier embedding from the ResponseWriter interface
  • Replace w.CloseNotify() with c.Request.Context().Done() in the Stream method
  • Update related tests accordingly

Motivation

http.CloseNotifier has been officially deprecated since Go 1.11. The Go documentation recommends using Request.Context() instead:

Deprecated: the CloseNotifier interface predates Go's context package. New code should use Request.Context instead.

Request.Context().Done() also covers a broader set of termination scenarios (timeout, cancellation) beyond just client disconnection.

Changes

response_writer.go

  • Remove http.CloseNotifier embedding from the ResponseWriter interface
  • Delete the CloseNotify() method from responseWriter

context.go

  • Stream: replace clientGone := w.CloseNotify() with clientGone := c.Request.Context().Done()

context_test.go

  • Replace closeChannel chan bool + CloseNotify() in TestResponseRecorder with cancel context.CancelFunc
  • Update closeClient() to call r.cancel() instead of sending to a channel
  • Update CreateTestResponseRecorder() to return (*TestResponseRecorder, *http.Request)
  • Update call sites: TestContextStream, TestContextStreamWithClientGone, TestContextResetInHandler

response_writer_test.go

  • Remove compile-time interface check for http.CloseNotifier
  • Remove w.CloseNotify() panic test block

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 17, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.37%. Comparing base (3dc1cd6) to head (3c28f41).
⚠️ Report is 275 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4587      +/-   ##
==========================================
- Coverage   99.21%   98.37%   -0.85%     
==========================================
  Files          42       48       +6     
  Lines        3182     3136      -46     
==========================================
- Hits         3157     3085      -72     
- Misses         17       42      +25     
- Partials        8        9       +1     
Flag Coverage Δ
?
--ldflags="-checklinkname=0" -tags sonic 98.36% <100.00%> (?)
-tags go_json 98.29% <100.00%> (?)
-tags nomsgpack 98.35% <100.00%> (?)
go-1.18 ?
go-1.19 ?
go-1.20 ?
go-1.21 ?
go-1.25 98.37% <100.00%> (?)
go-1.26 98.37% <100.00%> (?)
macos-latest 98.37% <100.00%> (-0.85%) ⬇️
ubuntu-latest 98.37% <100.00%> (-0.85%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@haesuo566 haesuo566 changed the title fix: Remove deprecated http.CloseNotifier, use Request.Context().Done() in Stream #4586 fix: Remove deprecated http.CloseNotifier, use Request.Context().Done() in Stream Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove deprecated http.CloseNotifier and replace with Request.Context().Done()

1 participant