Skip to content

Conversation

burybell
Copy link

This PR updates the Context.Stream function to use Request.Context().Done() instead of the deprecated CloseNotify() method.

Changes:
Replace w.CloseNotify() with c.Request.Context().Done() for client disconnect signal.

Motivation:
CloseNotify is deprecated and unreliable in modern HTTP/2 environments or when the connection passes through certain proxies or gateways.

Request.Context().Done() provides a more robust and standard-compliant way to detect client disconnects.

Impact:
This change improves compatibility and correctness, especially when using HTTP/2 or reverse proxies.

Let me know if you'd prefer backward compatibility logic for older Gin versions or if further changes are needed.

@appleboy appleboy requested a review from Copilot May 21, 2025 00:29
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR replaces the deprecated CloseNotify() method with Request.Context().Done() to improve client disconnect detection, especially in HTTP/2 and reverse proxy environments.

  • Replaces w.CloseNotify() with c.Request.Context().Done() in the stream handler
  • Enhances compatibility and correctness for client disconnect detection
Comments suppressed due to low confidence (1)

context.go:1211

  • The switch to using Request.Context().Done() is a solid update over the deprecated CloseNotify(). Please ensure that c.Request is always non-nil and its context properly reflects cancellation in all deployment scenarios.
clientGone := c.Request.Context().Done()

@appleboy appleboy added this to the v1.11 milestone May 21, 2025
@appleboy appleboy modified the milestones: v1.11, v1.12 Jun 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants