Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🔥 feat: Improve and Optimize ShutdownWithContext Func #3162
base: main
Are you sure you want to change the base?
🔥 feat: Improve and Optimize ShutdownWithContext Func #3162
Changes from 2 commits
137da86
b41d084
e1ad8e9
a683166
a4a5831
424ecbb
98fbdff
796922f
e465b5b
ee866ec
e0a56be
d01a09e
750a7fa
2ea0bb3
b9509fe
c2792e7
18111e5
83ea43d
66dcb42
f3902c5
da193ac
0a92125
b0bc70c
44cbc62
0e99032
a32bddd
5df1c89
da8c54d
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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 Data Race on
shutdownHookCalled
VariableThe
shutdownHookCalled
boolean is accessed by multiple goroutines without proper synchronization, which could lead to a data race. In Go, variables shared between goroutines should be protected using synchronization mechanisms like channels, mutexes, or atomic operations.Suggested Fix: Use an Atomic Variable
Replace
shutdownHookCalled
with anint32
and useatomic.StoreInt32
andatomic.LoadInt32
for thread-safe operations.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.
why do we need a sleep here? i think it's arbitrary since we already wait for clientDone channel
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.
This sleep is to ensure that our server has started processing the request. Although we have confirmed that the client has sent the request through <-clientDone, this means that the request has been sent to the server's listening port, and there is no guarantee that the server's processing coroutine has been sent. Start processing the request, so I think sleep 100 * Millisecond is required here as well.
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.
Ensure Proper Context Cancellation
The context created with
context.WithTimeout
should have its cancellation function deferred immediately to prevent potential resource leaks, even if an error occurs before the defer statement is reached.Suggested Improvement
Move the
defer cancel()
directly after context creation.📝 Committable suggestion
Check failure on line 906 in app_test.go
GitHub Actions / lint
Check failure on line 907 in app_test.go
GitHub Actions / lint
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.
🛠️ Refactor suggestion
Avoid Skipping Server Error Handling
Using a
default
case in theselect
statement may cause the test to proceed without waiting for the server to shut down, potentially leading to flaky tests. It's important to handle the server error explicitly.Suggested Fix: Remove the
default
CaseThis ensures the test waits for
serverErr
to receive an error or completes the shutdown process.📝 Committable suggestion