[PR #3504] [MERGED] service.Run supports passing in context #4766

Closed
opened 2026-05-05 14:48:21 -06:00 by gitea-mirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/fatedier/frp/pull/3504
Author: @fatedier
Created: 6/29/2023
Status: Merged
Merged: 6/29/2023
Merged by: @fatedier

Base: devHead: fix-2581


📝 Commits (1)

  • d50e432 service.Run supports passing in context

📊 Changes

5 files changed (+39 additions, -18 deletions)

View changed files

📝 .github/pull_request_template.md (+0 -4)
📝 client/service.go (+15 -6)
📝 cmd/frpc/sub/root.go (+2 -1)
📝 cmd/frps/root.go (+2 -1)
📝 server/service.go (+20 -6)

📄 Description

Summary

🤖 Generated by Copilot at 0fd5042

This pull request refactors the context management of the client and server packages, by passing contexts to the Run methods of the Service structs. This allows for graceful shutdown and cancellation of the services, and improves the consistency and readability of the code. It also updates the cmd/frpc and cmd/frps commands to use the context package and pass contexts to the services.

WHY

Fix #2581

Walkthrough

🤖 Generated by Copilot at 0fd5042

  • Pass context as argument to Run method of Service struct in client and server packages, and create new context with cancel from it (link, link, link, link)
  • Remove ctx and cancel fields from Service struct in client and server packages, and store them as local variables in Run method (link, link, link, link)
  • Close service or server if context is done and exit flag is not set in client package, or if context is done in server package (link, link)
  • Set svr.ctl and svr.cancel to nil after closing them in GracefulClose method of Service struct in client package, and check for nil before calling them (link)
  • Set svr.listener and svr.tlsConfig to nil after closing them in Close method of Service struct in server package, and check for nil before calling svr.cancel (link)
  • Clarify comment in keepControllerWorking function of client package to reflect actual delay in reconnecting to server (link)

🔄 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/fatedier/frp/pull/3504 **Author:** [@fatedier](https://github.com/fatedier) **Created:** 6/29/2023 **Status:** ✅ Merged **Merged:** 6/29/2023 **Merged by:** [@fatedier](https://github.com/fatedier) **Base:** `dev` ← **Head:** `fix-2581` --- ### 📝 Commits (1) - [`d50e432`](https://github.com/fatedier/frp/commit/d50e432ea7da4a365a7045dd7d7b5848d1cd9446) service.Run supports passing in context ### 📊 Changes **5 files changed** (+39 additions, -18 deletions) <details> <summary>View changed files</summary> 📝 `.github/pull_request_template.md` (+0 -4) 📝 `client/service.go` (+15 -6) 📝 `cmd/frpc/sub/root.go` (+2 -1) 📝 `cmd/frps/root.go` (+2 -1) 📝 `server/service.go` (+20 -6) </details> ### 📄 Description ### Summary <!-- copilot:summary --> ### <samp>🤖 Generated by Copilot at 0fd5042</samp> This pull request refactors the context management of the client and server packages, by passing contexts to the `Run` methods of the `Service` structs. This allows for graceful shutdown and cancellation of the services, and improves the consistency and readability of the code. It also updates the `cmd/frpc` and `cmd/frps` commands to use the context package and pass contexts to the services. ### WHY Fix #2581 ### Walkthrough <!-- copilot:walkthrough --> ### <samp>🤖 Generated by Copilot at 0fd5042</samp> * Pass context as argument to `Run` method of `Service` struct in `client` and `server` packages, and create new context with cancel from it ([link](https://github.com/fatedier/frp/pull/3504/files?diff=unified&w=0#diff-37135e06c87eb7f15648ee3df06d54a2a52cab735ea4110e81610945fe38f7d4L109-R111), [link](https://github.com/fatedier/frp/pull/3504/files?diff=unified&w=0#diff-7cd1def768b5bcc52b79dd84b45271a4f4c0604d574564e6b60e8f2770691394L332-R334), [link](https://github.com/fatedier/frp/pull/3504/files?diff=unified&w=0#diff-204e5524f2c503fa2d88a3c6b30cded3937dabf8bb0d9fac3e8da9daa7824638L236-R237), [link](https://github.com/fatedier/frp/pull/3504/files?diff=unified&w=0#diff-da9862f2cd2796cfe7de4e1ae6a3bb45517c8666a780ed932adc177b1878cf69L213-R214)) * Remove `ctx` and `cancel` fields from `Service` struct in `client` and `server` packages, and store them as local variables in `Run` method ([link](https://github.com/fatedier/frp/pull/3504/files?diff=unified&w=0#diff-37135e06c87eb7f15648ee3df06d54a2a52cab735ea4110e81610945fe38f7d4L96-R96), [link](https://github.com/fatedier/frp/pull/3504/files?diff=unified&w=0#diff-37135e06c87eb7f15648ee3df06d54a2a52cab735ea4110e81610945fe38f7d4L89), [link](https://github.com/fatedier/frp/pull/3504/files?diff=unified&w=0#diff-7cd1def768b5bcc52b79dd84b45271a4f4c0604d574564e6b60e8f2770691394L132-R131), [link](https://github.com/fatedier/frp/pull/3504/files?diff=unified&w=0#diff-7cd1def768b5bcc52b79dd84b45271a4f4c0604d574564e6b60e8f2770691394L118)) * Close service or server if context is done and exit flag is not set in `client` package, or if context is done in `server` package ([link](https://github.com/fatedier/frp/pull/3504/files?diff=unified&w=0#diff-37135e06c87eb7f15648ee3df06d54a2a52cab735ea4110e81610945fe38f7d4R166-R169), [link](https://github.com/fatedier/frp/pull/3504/files?diff=unified&w=0#diff-7cd1def768b5bcc52b79dd84b45271a4f4c0604d574564e6b60e8f2770691394R348-R353)) * Set `svr.ctl` and `svr.cancel` to nil after closing them in `GracefulClose` method of `Service` struct in `client` package, and check for nil before calling them ([link](https://github.com/fatedier/frp/pull/3504/files?diff=unified&w=0#diff-37135e06c87eb7f15648ee3df06d54a2a52cab735ea4110e81610945fe38f7d4L325-R337)) * Set `svr.listener` and `svr.tlsConfig` to nil after closing them in `Close` method of `Service` struct in `server` package, and check for nil before calling `svr.cancel` ([link](https://github.com/fatedier/frp/pull/3504/files?diff=unified&w=0#diff-7cd1def768b5bcc52b79dd84b45271a4f4c0604d574564e6b60e8f2770691394L351-R380)) * Clarify comment in `keepControllerWorking` function of `client` package to reflect actual delay in reconnecting to server ([link](https://github.com/fatedier/frp/pull/3504/files?diff=unified&w=0#diff-37135e06c87eb7f15648ee3df06d54a2a52cab735ea4110e81610945fe38f7d4L185-R191)) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
gitea-mirror 2026-05-05 14:48:21 -06:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/frp#4766
No description provided.