-
Notifications
You must be signed in to change notification settings - Fork 244
Fix duplicated log entries #113
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 duplicated log entries #113
Conversation
Codecov Report
@@ Coverage Diff @@
## master #113 +/- ##
==========================================
+ Coverage 64.33% 64.48% +0.14%
==========================================
Files 24 24
Lines 2044 2061 +17
==========================================
+ Hits 1315 1329 +14
- Misses 579 581 +2
- Partials 150 151 +1
Continue to review full report at Codecov.
|
@Skarlso please have a look. This fixes the bug and also improves the general logging. Logs are now streamed to the disk every second. This improves the output a lot. |
@@ -474,6 +496,7 @@ func (s *Scheduler) executeScheduler(r *gaia.PipelineRun, pS Plugin) { | |||
for { | |||
select { | |||
case <-finished: | |||
close(pipelineFinished) |
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.
So, you'll need to get out of the habit of doing this. :) The close doesn't actually signal the channel that it's closed or something. This only HAPPENS to work because of the side effect of reading from a closed channel. Reading from a closed channel is allowed right now, and will just not read any value, but the leg of the select will still execute. However, that's a side effect behaviour.
The reasonable and polite thing to do to a channel if it's closed and you are the reader is to check wether you are receiving a value or you are receiving because it's closed.
For example:
select {
case _, ok := <-done:
if ok {
fmt.Println("received closing signal")
wg.Done() // do some behaviour here.
} else {
fmt.Println("the channel has been closed. terminating.")
}
default:
fmt.Println("doing nothing")
}
Why is this important? I could just put the wg.Done() into the leg and be done. Well, no. Because if that guy is in a for loop for example and there is nothing else, than that leg will run at least twice or three times before it actually terminates calling wg.Done() more often than it should and leaving wg in a negative count or less than it should be.
So please be aware of this and try not to signal a channel to finish by closing it and relying on a side effect to do the job. That side effect may be altered in future versions which would leave us unable to update without a refactor.
I hope this makes sense and doesn't sound overly picky. :) :)
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.
You are absolutely right. This is not really clean and might lead to weird bugs in the future. I have updated my PR. What do you think? 🤗
I'll do a quick manual then I'll merge it if everything is okay. :) |
Fixes #74