-
Notifications
You must be signed in to change notification settings - Fork 142
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
fix: Set Context properly #582
Conversation
I thinks there are 2 issues which you should fix in your code
@b00f what is your opinion? |
@@ -46,7 +47,9 @@ func NewNode(genDoc *genesis.Genesis, conf *config.Config, | |||
"version", version.Version(), | |||
"network", genDoc.ChainType()) | |||
|
|||
network, err := network.NewNetwork(conf.Network) | |||
ctx, cancel := context.WithCancel(context.Background()) |
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.
I think we need to add cancel to the node structure and call it when the node is shutting down
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.
yes, I can do it, but just tell me what should I do about the network module cancel?
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.
I did that but there is an issue, all stuff is fine but I got this warning:
the cancel function is not used on all paths (possible context leak)
I already called cancel in the stop node method.
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.
I did that but there is an issue, all stuff is fine but I got this warning:
the cancel function is not used on all paths (possible context leak)
I already called cancel in the stop node method.
Has the Stop method been used anywhere?
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.
I don't think so.
where should I use it?
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.
in GUI: CTA Exit
in CLI: on interrupt signal
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.
ok
I will add it
sure, I think its true |
@Ja7ad please review this PR |
@b00f I added some changes! |
Codecov Report
@@ Coverage Diff @@
## main #582 +/- ##
==========================================
- Coverage 83.53% 83.49% -0.05%
==========================================
Files 154 154
Lines 7252 7257 +5
==========================================
+ Hits 6058 6059 +1
- Misses 915 918 +3
- Partials 279 280 +1 |
@@ -104,7 +106,8 @@ func readData(t *testing.T, r io.ReadCloser, len int) []byte { | |||
} | |||
|
|||
func TestStoppingNetwork(t *testing.T) { | |||
net, err := NewNetwork(testConfig()) | |||
ctx := context.Background() |
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.
for test you can use context.ToDo
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.
is that the just thing I should change?
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.
is that the just thing I should change?
No, in other test change Background to ToDo.
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.
ok, I will change it too
should I remove defer func for cancel() in node.go?
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.
ok, I will change it too should I remove defer func for cancel() in node.go?
Yes
@b00f should we close this and follow the steps I provided and make a new pr? |
Better to have a new PR. Thanks |
okay, after the script, I will send a new PR for it. |
Personally, I don't like using As discuss here suggest having three methods in all struct as an object to solve the object life cycle. When we have the For a more deep discussion, I think it is better to have a meeting if you agree with the overall idea. |
We have some DEV-meeting from time to time with the development team. There's no specific time for these meetings, but we can discuss it at the next DEV-meeting. Thanks for bringing it up @OmidHekayati |
Description
This PR introduces a global context and passed it to all modules when the node starts. By shutting down the node, the context will be cancelled and all modules will receive the cancellation signal.
Related issue(s)