Merge pull request #9991 from hashicorp/b-amazon-ssm-infinite-loop

amazon/ssm_driver: Update log polling logic
This commit is contained in:
Megan Marsh 2020-09-24 09:55:39 -07:00 committed by GitHub
commit d66b358100
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 3 deletions

View File

@ -46,7 +46,7 @@ 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) {
log.Printf("Starting PortForwarding session to instance %q with following params %v", aws.StringValue(input.Target), input.Parameters) log.Printf("Starting PortForwarding session to instance %q", aws.StringValue(input.Target))
var output *ssm.StartSessionOutput var output *ssm.StartSessionOutput
err := retry.Config{ err := retry.Config{
@ -110,15 +110,30 @@ func (d *SSMDriver) openTunnelForSession(ctx context.Context) error {
select { select {
case <-ctx.Done(): case <-ctx.Done():
return return
case output := <-stderrCh: case output, ok := <-stderrCh:
if !ok {
stderrCh = nil
break
}
if output != "" { if output != "" {
log.Printf("[ERROR] %s: %s", prefix, output) log.Printf("[ERROR] %s: %s", prefix, output)
} }
case output := <-stdoutCh: case output, ok := <-stdoutCh:
if !ok {
stdoutCh = nil
break
}
if output != "" { if output != "" {
log.Printf("[DEBUG] %s: %s", prefix, output) log.Printf("[DEBUG] %s: %s", prefix, output)
} }
} }
if stdoutCh == nil && stderrCh == nil {
log.Printf("[DEBUG] %s: %s", prefix, "active session has been terminated; stopping all log polling processes.")
return
}
} }
}(ctx, sessionManagerPluginName) }(ctx, sessionManagerPluginName)