mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Update how runsc's port-forward command is terminated.
It currently expects all 3 events to happen to exit the command, the container is killed, local port forward is compeleted, a termination signal is caught. One can only terminate the command expecting both termination signal (e.g. ctrl + c) and the container being killed. Instead, the ideal behavior is that the command exits on either of previous 2 events. The local port forward goroutine is blocked until the context's cancel function is called. Thus, we just have the waitgroup to wait for the completion of the local port forward task. PiperOrigin-RevId: 668168948
This commit is contained in:
@@ -128,7 +128,7 @@ func (p *PortForward) Execute(ctx context.Context, f *flag.FlagSet, args ...any)
|
||||
// Start port forwarding with the local port.
|
||||
var wg sync.WaitGroup
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
wg.Add(3)
|
||||
wg.Add(1)
|
||||
go func(localPort, portNum int) {
|
||||
defer cancel()
|
||||
defer wg.Done()
|
||||
@@ -141,7 +141,6 @@ func (p *PortForward) Execute(ctx context.Context, f *flag.FlagSet, args ...any)
|
||||
|
||||
// Exit port forwarding if the container exits.
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
// Cancel port forwarding after Wait returns regardless of return
|
||||
// value as err may indicate sandbox has terminated already.
|
||||
_, _ = c.Wait()
|
||||
@@ -151,7 +150,6 @@ func (p *PortForward) Execute(ctx context.Context, f *flag.FlagSet, args ...any)
|
||||
|
||||
// Wait for ^C from the user.
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
sig := waitSignal()
|
||||
fmt.Printf("Got %v, Exiting...\n", sig)
|
||||
cancel()
|
||||
|
||||
Reference in New Issue
Block a user