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.
Replace child stop channels with cancelable contexts
Commit 5d6b136 added child stop channels to stop the network policy handlers independently from the network controller when the policy is deleted while also stopping them if the network controller is stopped. Unfortunately when both things happen at the same time, one of those events will end up attempting to close a closed channel which will panic. Introduce a CancelableContext utility that will wrap a cancelable context that can be chained to achieve the same effect. Signed-off-by: Jaime Caamaño Ruiz <jcaamano@redhat.com>
- Loading branch information
Showing
13 changed files
with
71 additions
and
48 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
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,36 @@ | ||
package util | ||
|
||
import "context" | ||
|
||
// CancelableContext utility wraps a context that can be canceled | ||
type CancelableContext struct { | ||
ctx context.Context | ||
cancel context.CancelFunc | ||
} | ||
|
||
// Done returns a channel that is closed when this or any parent context is | ||
// canceled | ||
func (ctx *CancelableContext) Done() <-chan struct{} { | ||
return ctx.ctx.Done() | ||
} | ||
|
||
// Cancel this context | ||
func (ctx *CancelableContext) Cancel() { | ||
ctx.cancel() | ||
} | ||
|
||
func NewCancelableContext() CancelableContext { | ||
return newCancelableContext(context.Background()) | ||
} | ||
|
||
func NewCancelableContextChild(ctx CancelableContext) CancelableContext { | ||
return newCancelableContext(ctx.ctx) | ||
} | ||
|
||
func newCancelableContext(ctx context.Context) CancelableContext { | ||
ctx, cancel := context.WithCancel(ctx) | ||
return CancelableContext{ | ||
ctx: ctx, | ||
cancel: cancel, | ||
} | ||
} |
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