[PR #37] feat: base context + errgroup; propagate cancellation; gracefu… #36

Open
opened 2025-11-19 07:03:48 -06:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/fosrl/gerbil/pull/37
Author: @LaurenceJJones
Created: 11/16/2025
Status: 🔄 Open

Base: mainHead: enhancement/errgroup-context-propagation


📝 Commits (1)

  • 697f413 enhancement: base context + errgroup; propagate cancellation; graceful shutdown

📊 Changes

2 files changed (+174 additions, -71 deletions)

View changed files

📝 main.go (+57 -18)
📝 relay/relay.go (+117 -53)

📄 Description

…l shutdown

Community Contribution License Agreement

By creating this pull request, I grant the project maintainers an unlimited,
perpetual license to use, modify, and redistribute these contributions under any terms they
choose, including both the AGPLv3 and the Fossorial Commercial license terms. I
represent that I have the right to grant this license for all contributed content.

Description

  • main: add base context via signal.NotifyContext; establish errgroup and use it to supervise background tasks; convert ticker to context-aware periodicBandwidthCheck; run HTTP server under errgroup and add graceful shutdown; treat context.Canceled as normal exit
  • relay: thread parent context through UDPProxyServer; add cancel func; make packet reader, workers, and cleanup tickers exit on ctx.Done; Stop cancels, closes listener and downstream UDP connections, and closes packet channel to drain workers
  • proxy: drop earlier parent context hook for SNI proxy per review; rely on existing Stop() for graceful shutdown

Benefits:

  • unified lifecycle and deterministic shutdown across components
  • prevents leaked goroutines/tickers and closes sockets cleanly
  • consolidated error handling via g.Wait(), with context cancellation treated as non-error
  • sets foundation for child errgroups and future structured concurrency

How to test?

Purely go semantics on handling contexts and routines in a way that if an error occur in a component or if the process is informed to shutdown it will do so in an orderly fashion and without leaking tickers/routines.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/fosrl/gerbil/pull/37 **Author:** [@LaurenceJJones](https://github.com/LaurenceJJones) **Created:** 11/16/2025 **Status:** 🔄 Open **Base:** `main` ← **Head:** `enhancement/errgroup-context-propagation` --- ### 📝 Commits (1) - [`697f413`](https://github.com/fosrl/gerbil/commit/697f4131e7e5b3dab3fba49361fb5a349e60cd19) enhancement: base context + errgroup; propagate cancellation; graceful shutdown ### 📊 Changes **2 files changed** (+174 additions, -71 deletions) <details> <summary>View changed files</summary> 📝 `main.go` (+57 -18) 📝 `relay/relay.go` (+117 -53) </details> ### 📄 Description …l shutdown ## Community Contribution License Agreement By creating this pull request, I grant the project maintainers an unlimited, perpetual license to use, modify, and redistribute these contributions under any terms they choose, including both the AGPLv3 and the Fossorial Commercial license terms. I represent that I have the right to grant this license for all contributed content. ## Description - main: add base context via signal.NotifyContext; establish errgroup and use it to supervise background tasks; convert ticker to context-aware periodicBandwidthCheck; run HTTP server under errgroup and add graceful shutdown; treat context.Canceled as normal exit - relay: thread parent context through UDPProxyServer; add cancel func; make packet reader, workers, and cleanup tickers exit on ctx.Done; Stop cancels, closes listener and downstream UDP connections, and closes packet channel to drain workers - proxy: drop earlier parent context hook for SNI proxy per review; rely on existing Stop() for graceful shutdown Benefits: - unified lifecycle and deterministic shutdown across components - prevents leaked goroutines/tickers and closes sockets cleanly - consolidated error handling via g.Wait(), with context cancellation treated as non-error - sets foundation for child errgroups and future structured concurrency ## How to test? Purely go semantics on handling contexts and routines in a way that if an error occur in a component or if the process is informed to shutdown it will do so in an orderly fashion and without leaking tickers/routines. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2025-11-19 07:03:48 -06:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gerbil#36