Skip to content

Conversation

michelvocks
Copy link
Member

Fixes #74

@michelvocks michelvocks added the Needs Work The PR still requires some work from the submitter. label Sep 24, 2018
@michelvocks michelvocks self-assigned this Sep 24, 2018
@codecov-io
Copy link

codecov-io commented Sep 24, 2018

Codecov Report

Merging #113 into master will increase coverage by 0.14%.
The diff coverage is 72.72%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
plugin/plugin.go 66.93% <42.85%> (-0.57%) ⬇️
scheduler/scheduler.go 73.4% <86.66%> (+0.86%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 767ef36...2974391. Read the comment docs.

@michelvocks michelvocks added Ready To Merge PR is ready to be merged into master needs review and removed Needs Work The PR still requires some work from the submitter. labels Sep 25, 2018
@michelvocks michelvocks requested a review from Skarlso September 25, 2018 18:57
@michelvocks
Copy link
Member Author

@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.

@michelvocks michelvocks changed the title [WIP] Fix duplicated log entries Fix duplicated log entries Sep 25, 2018
@@ -474,6 +496,7 @@ func (s *Scheduler) executeScheduler(r *gaia.PipelineRun, pS Plugin) {
for {
select {
case <-finished:
close(pipelineFinished)
Copy link
Member

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. :) :)

Copy link
Member Author

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? 🤗

@Skarlso
Copy link
Member

Skarlso commented Sep 26, 2018

I'll do a quick manual then I'll merge it if everything is okay. :)

@Skarlso Skarlso merged commit 753ee64 into gaia-pipeline:master Sep 26, 2018
@michelvocks michelvocks deleted the fix_duplicated_log_entries branch September 26, 2018 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs review Ready To Merge PR is ready to be merged into master
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants