-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 #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.
- Loading branch information
Showing
3 changed files
with
32 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters