Remove waitgroups

This commit is contained in:
Wilken Rivera 2020-10-07 11:27:23 -04:00
parent eb11009e2a
commit dff9cde775
1 changed files with 0 additions and 12 deletions

View File

@ -7,7 +7,6 @@ import (
"log" "log"
"os/exec" "os/exec"
"strings" "strings"
"sync"
"time" "time"
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
@ -39,7 +38,6 @@ type SSMDriver struct {
retryConnection chan bool retryConnection chan bool
retryAfterTermination chan bool retryAfterTermination chan bool
wg sync.WaitGroup
} }
func NewSSMDriver(config SSMDriverConfig) *SSMDriver { func NewSSMDriver(config SSMDriverConfig) *SSMDriver {
@ -52,8 +50,6 @@ func NewSSMDriver(config SSMDriverConfig) *SSMDriver {
// not wish to manage the session manually calling StopSession on a instance of this driver will terminate the active session // not wish to manage the session manually calling StopSession on a instance of this driver will terminate the active session
// created from calling StartSession. // created from calling StartSession.
func (d *SSMDriver) StartSession(ctx context.Context, input ssm.StartSessionInput) (*ssm.StartSessionOutput, error) { func (d *SSMDriver) StartSession(ctx context.Context, input ssm.StartSessionInput) (*ssm.StartSessionOutput, error) {
d.wg.Add(1)
defer d.wg.Done()
log.Printf("Starting PortForwarding session to instance %q", aws.StringValue(input.Target)) log.Printf("Starting PortForwarding session to instance %q", aws.StringValue(input.Target))
output, err := d.StartSessionWithContext(ctx, input) output, err := d.StartSessionWithContext(ctx, input)
@ -75,7 +71,6 @@ func (d *SSMDriver) StartSession(ctx context.Context, input ssm.StartSessionInpu
return return
} }
if r { if r {
d.wg.Wait()
log.Printf("[DEBUG] Restablishing SSM connection") log.Printf("[DEBUG] Restablishing SSM connection")
_, _ = driver.StartSession(ctx, input) _, _ = driver.StartSession(ctx, input)
// End this routine. Another routine will start. // End this routine. Another routine will start.
@ -88,7 +83,6 @@ func (d *SSMDriver) StartSession(ctx context.Context, input ssm.StartSessionInpu
// Tunnel is still open an we want to try to reconnect // Tunnel is still open an we want to try to reconnect
if r { if r {
d.wg.Wait()
log.Printf("[DEBUG] Retrying to establish SSM connection") log.Printf("[DEBUG] Retrying to establish SSM connection")
_, err := driver.StartSessionWithContext(ctx, input) _, err := driver.StartSessionWithContext(ctx, input)
if err != nil { if err != nil {
@ -114,9 +108,6 @@ func (d *SSMDriver) StartSession(ctx context.Context, input ssm.StartSessionInpu
} }
func (d *SSMDriver) StartSessionWithContext(ctx context.Context, input ssm.StartSessionInput) (*ssm.StartSessionOutput, error) { func (d *SSMDriver) StartSessionWithContext(ctx context.Context, input ssm.StartSessionInput) (*ssm.StartSessionOutput, error) {
d.wg.Add(1)
defer d.wg.Done()
var output *ssm.StartSessionOutput var output *ssm.StartSessionOutput
err := retry.Config{ err := retry.Config{
ShouldRetry: func(err error) bool { return IsAWSErr(err, "TargetNotConnected", "") }, ShouldRetry: func(err error) bool { return IsAWSErr(err, "TargetNotConnected", "") },
@ -225,9 +216,6 @@ func isRetryableError(output string) bool {
// StopSession terminates an active Session Manager session // StopSession terminates an active Session Manager session
func (d *SSMDriver) StopSession() error { func (d *SSMDriver) StopSession() error {
d.wg.Add(1)
defer d.wg.Done()
if d.session == nil || d.session.SessionId == nil { if d.session == nil || d.session.SessionId == nil {
return fmt.Errorf("Unable to find a valid session to instance %q; skipping the termination step", return fmt.Errorf("Unable to find a valid session to instance %q; skipping the termination step",
aws.StringValue(d.sessionParams.Target)) aws.StringValue(d.sessionParams.Target))