-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
π₯ feat: Improve and Optimize ShutdownWithContext Func (#3162)
* feat: Optimize ShutdownWithContext method in app.go - Reorder mutex lock acquisition to the start of the function - Early return if server is not running - Use defer for executing shutdown hooks - Simplify nil check for hooks - Remove TODO comment This commit improves the readability, robustness, and execution order of the shutdown process. It ensures consistent state throughout the shutdown and guarantees hook execution even in error cases. * feat: Enhance ShutdownWithContext test for improved reliability - Add shutdown hook verification - Implement better synchronization with channels - Improve error handling and assertions - Adjust timeouts for more consistent results - Add server state check after shutdown attempt - Include comments explaining expected behavior This commit improves the comprehensiveness and reliability of the ShutdownWithContext test, ensuring proper verification of shutdown hooks, timeout behavior, and server state during long-running requests. * π Doc: update the docs to explain shutdown & hook execution order * π©Ή Fix: Possible Data Race on shutdownHookCalled Variable * π©Ή Fix: Remove the default Case * π©Ή Fix: Import sync/atomic * π©Ή Fix: golangci-lint problem * π¨ Style: add block in api.md * π©Ή Fix: go mod tidy * feat: Optimize ShutdownWithContext method in app.go - Reorder mutex lock acquisition to the start of the function - Early return if server is not running - Use defer for executing shutdown hooks - Simplify nil check for hooks - Remove TODO comment This commit improves the readability, robustness, and execution order of the shutdown process. It ensures consistent state throughout the shutdown and guarantees hook execution even in error cases. * feat: Enhance ShutdownWithContext test for improved reliability - Add shutdown hook verification - Implement better synchronization with channels - Improve error handling and assertions - Adjust timeouts for more consistent results - Add server state check after shutdown attempt - Include comments explaining expected behavior This commit improves the comprehensiveness and reliability of the ShutdownWithContext test, ensuring proper verification of shutdown hooks, timeout behavior, and server state during long-running requests. * π Doc: update the docs to explain shutdown & hook execution order * π©Ή Fix: Possible Data Race on shutdownHookCalled Variable * π©Ή Fix: Remove the default Case * π©Ή Fix: Import sync/atomic * π©Ή Fix: golangci-lint problem * π¨ Style: add block in api.md * π©Ή Fix: go mod tidy * β»οΈ Refactor: replaced OnShutdown by OnPreShutdown and OnPostShutdown * β»οΈ Refactor: streamline post-shutdown hook execution in graceful shutdown process * π¨ Test: add test for gracefulShutdown * π₯ Feature: Using executeOnPreShutdownHooks and executeOnPostShutdownHooks Instead of OnShutdownSuccess and OnShutdownError * π©Ή Fix: deal Listener err * π©Ή Fix: go lint error * π©Ή Fix: reduced memory alignment * π©Ή Fix: reduced memory alignment * π©Ή Fix: context should be created inside the concatenation. * π Doc: update what_new.md and hooks.md * β»οΈ Refactor: use blocking channel instead of time.Sleep * π©Ή Fix: Improve synchronization in error propagation test. * π©Ή Fix: Replace sleep with proper synchronization. * π©Ή Fix: Server but not shut down properly * π©Ή Fix: Using channels to synchronize and pass results * π©Ή Fix: timeout with long running request * π Doc: remove OnShutdownError and OnShutdownSuccess from fiber.md * Update hooks.md * π¨ Test: Add graceful shutdown timeout error test case * π Doc: Restructure hooks documentation for OnPreShutdown and OnPostShutdown * π Doc: Remove extra whitespace in hooks documentation --------- Co-authored-by: yingjie.huang <yingjie.huang@fosunhn.net> Co-authored-by: Juan Calderon-Perez <835733+gaby@users.noreply.github.com>
- Loading branch information
1 parent
252a022
commit 4b62d3d
Showing
9 changed files
with
421 additions
and
251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
4b62d3d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold
1.50
.Benchmark_Ctx_Send
6.862
ns/op 0 B/op 0 allocs/op4.364
ns/op 0 B/op 0 allocs/op1.57
Benchmark_Ctx_Send - ns/op
6.862
ns/op4.364
ns/op1.57
Benchmark_Utils_GetOffer/1_parameter
224.6
ns/op 0 B/op 0 allocs/op134.2
ns/op 0 B/op 0 allocs/op1.67
Benchmark_Utils_GetOffer/1_parameter - ns/op
224.6
ns/op134.2
ns/op1.67
14
allocs/opBenchmark_Middleware_BasicAuth - B/op
80
B/op48
B/op1.67
Benchmark_Middleware_BasicAuth - allocs/op
5
allocs/op3
allocs/op1.67
Benchmark_Middleware_BasicAuth_Upper - B/op
80
B/op48
B/op1.67
Benchmark_Middleware_BasicAuth_Upper - allocs/op
5
allocs/op3
allocs/op1.67
Benchmark_CORS_NewHandler - B/op
16
B/op0
B/op+β
Benchmark_CORS_NewHandler - allocs/op
1
allocs/op0
allocs/op+β
Benchmark_CORS_NewHandlerSingleOrigin - B/op
16
B/op0
B/op+β
Benchmark_CORS_NewHandlerSingleOrigin - allocs/op
1
allocs/op0
allocs/op+β
Benchmark_CORS_NewHandlerPreflight - B/op
104
B/op0
B/op+β
Benchmark_CORS_NewHandlerPreflight - allocs/op
5
allocs/op0
allocs/op+β
Benchmark_CORS_NewHandlerPreflightSingleOrigin - B/op
104
B/op0
B/op+β
Benchmark_CORS_NewHandlerPreflightSingleOrigin - allocs/op
5
allocs/op0
allocs/op+β
Benchmark_CORS_NewHandlerPreflightWildcard - B/op
104
B/op0
B/op+β
Benchmark_CORS_NewHandlerPreflightWildcard - allocs/op
5
allocs/op0
allocs/op+β
Benchmark_Middleware_CSRF_GenerateToken - B/op
514
B/op322
B/op1.60
Benchmark_Middleware_CSRF_GenerateToken - allocs/op
10
allocs/op6
allocs/op1.67
This comment was automatically generated by workflow using github-action-benchmark.