예제 #1
0
// startSession creates a session with ACS and handles requests from ACS
// It also tries to repeatedly connect to ACS when disconnected
func startSession(ctx context.Context, args StartSessionArguments, backoff *utils.SimpleBackoff, acsResources sessionResources) error {
	for {
		acsError := startSessionOnce(ctx, args, backoff, acsResources)
		select {
		case <-ctx.Done():
			return ctx.Err()
		default:
		}

		if acsError == nil || acsError == io.EOF {
			backoff.Reset()
		} else {
			seelog.Infof("Error from acs; backing off, err: %v", acsError)
			args.time().Sleep(backoff.Duration())
		}
	}
}
// startSession creates a session with ACS and handles requests from ACS
// It also tries to repeatedly connect to ACS when disconnected
func startSession(ctx context.Context, args StartSessionArguments, backoff *utils.SimpleBackoff, acsResources sessionResources) error {
	for {
		acsError := startSessionOnce(ctx, args, backoff, acsResources)
		select {
		case <-ctx.Done():
			return ctx.Err()
		default:
		}

		if acsError == nil || acsError == io.EOF {
			backoff.Reset()
		} else if strings.HasPrefix(acsError.Error(), "InactiveInstanceException:") {
			seelog.Debug("Container instance is deregistered, notifying listeners")
			err := args.DeregisterInstanceEventStream.WriteToEventStream(struct{}{})
			if err != nil {
				seelog.Debugf("Failed to write to deregister container instance event stream, err: %v", err)
			}
		} else {
			seelog.Infof("Error from acs; backing off, err: %v", acsError)
			args.time().Sleep(backoff.Duration())
		}
	}
}