-
Notifications
You must be signed in to change notification settings - Fork 243
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
Use sync/atomic to keep tab on go routines #5961
Use sync/atomic to keep tab on go routines #5961
Conversation
Signed-off-by: Dharmit Shah <shahdharmit@gmail.com> As a result of the code pushed in #5942, `odo logs --follow` would hang if user executed it without pushing the component in either dev or deploy modes. This was not a problem before that PR was merged. This was caused because below code would not get executed in business layer if user was using follow mode: ``` if !follow { doneChan <- struct{}{} } ``` The reason we didn't execute it for follow mode was that it prematurely exited and often didn't print the logs of all the containers. This PR uses `sync/atomic` to keep a tab on go routines started for `odo logs --follow` instead of using `sync.WaitGroup`, and checks if no go routines are running before it exits. This enables us to use `doneChan <- struct{}{}` in business layer irrespective of user running `odo logs` with or without follow mode. Why not use `wg.Wait()` as first statement instead in `case <-events.Done:`? This is because `wg.Wait()` is a blocking call and won't be called upon each time a go routine for `odo logs --follow` is done (`wg.Done()`). This leads to same problem as that fixed by PR 5942, which is that `odo logs --follow` won't exit even if the underlying odo component was deleted.
✅ Deploy Preview for odo-docusaurus-preview canceled.
|
Signed-off-by: Dharmit Shah <shahdharmit@gmail.com> `go vet` complains about direct assignment to an atomic value. Hence, an anonymous struct to fix the problem.
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
/approve and thanks for the fix! |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: cdrage The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
* Use sync/atomic to keep tab on go routines Signed-off-by: Dharmit Shah <shahdharmit@gmail.com> As a result of the code pushed in redhat-developer#5942, `odo logs --follow` would hang if user executed it without pushing the component in either dev or deploy modes. This was not a problem before that PR was merged. This was caused because below code would not get executed in business layer if user was using follow mode: ``` if !follow { doneChan <- struct{}{} } ``` The reason we didn't execute it for follow mode was that it prematurely exited and often didn't print the logs of all the containers. This PR uses `sync/atomic` to keep a tab on go routines started for `odo logs --follow` instead of using `sync.WaitGroup`, and checks if no go routines are running before it exits. This enables us to use `doneChan <- struct{}{}` in business layer irrespective of user running `odo logs` with or without follow mode. Why not use `wg.Wait()` as first statement instead in `case <-events.Done:`? This is because `wg.Wait()` is a blocking call and won't be called upon each time a go routine for `odo logs --follow` is done (`wg.Done()`). This leads to same problem as that fixed by PR 5942, which is that `odo logs --follow` won't exit even if the underlying odo component was deleted. * Use a struct instead of int64 for atomic Signed-off-by: Dharmit Shah <shahdharmit@gmail.com> `go vet` complains about direct assignment to an atomic value. Hence, an anonymous struct to fix the problem.
Signed-off-by: Dharmit Shah shahdharmit@gmail.com
What type of PR is this:
/kind bug
What does this PR do / why we need it:
As a result of the code pushed in #5942,
odo logs --follow
would hangif user executed it without pushing the component in either dev or
deploy modes. This was not a problem before that PR was merged.
This was caused because below code would not get executed in business
layer if user was using follow mode:
The reason we didn't execute it for follow mode was that it prematurely
exited and often didn't print the logs of all the containers.
This PR uses
sync/atomic
to keep a tab on go routines started forodo logs --follow
instead of usingsync.WaitGroup
, and checks if nogo routines are running before it exits. This enables us to use
doneChan <- struct{}{}
in business layer irrespective of user runningodo logs
with or without follow mode.Why not use
wg.Wait()
as first statement instead incase <-events.Done:
? This is becausewg.Wait()
is a blocking calland won't be called upon each time a go routine for
odo logs --follow
is done (
wg.Done()
). This leads to same problem as that fixed by PR5942, which is that
odo logs --follow
won't exit even if theunderlying odo component was deleted.
Which issue(s) this PR fixes:
Fixes part of #5872
PR acceptance criteria:
Unit test
Integration test
Documentation
How to test changes / Special notes to the reviewer: