forked from openshift/ovn-kubernetes
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We used to pass oc.stopChan to the retryFramework for network policy handlers, but that means that retry loop for failed objects will not be stopped on network policy delete, therefore leaking goroutines. Create getChildStopChan function to pass stop signal both on oc and network policy delete. Signed-off-by: Nadia Pinaeva <npinaeva@redhat.com>
- Loading branch information
Showing
6 changed files
with
135 additions
and
8 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package util | ||
|
||
// GetChildStopChan returns a new channel that doesn't affect parentStopChan, but will be closed when | ||
// parentStopChan is closed. May be used for child goroutines that may need to be stopped with the main goroutine or | ||
// separately. | ||
func GetChildStopChan(parentStopChan <-chan struct{}) chan struct{} { | ||
childStopChan := make(chan struct{}) | ||
|
||
select { | ||
case <-parentStopChan: | ||
// parent is already canceled | ||
close(childStopChan) | ||
return childStopChan | ||
default: | ||
} | ||
|
||
go func() { | ||
select { | ||
case <-parentStopChan: | ||
close(childStopChan) | ||
return | ||
case <-childStopChan: | ||
return | ||
} | ||
}() | ||
return childStopChan | ||
} |