Skip to content

Listener gets into crash loop with createSession 409 error #3209

Closed

Description

@int128

Checks

Controller Version

0.8.1

Deployment Method

ArgoCD

Checks

  • This isn't a question or user support case (For Q&A and community support, go to Discussions).
  • I've read the Changelog before submitting this issue and I'm sure it's not due to any recently-introduced backward-incompatible changes

To Reproduce

We have 2 Kubernetes clusters.

1. Install the controller into `arc-systems` namespace of cluster A
2. Install the controller into `arc-systems` namespace of cluster B
3. Add a gha-runner-scale-set into `arc-runners` namespace of cluster A. The runner belongs to a repository
4. Add a gha-runner-scale-set into `arc-runners` namespace of cluster B. The runner belongs to the same repository, but has the different runner name

Describe the bug

A listener pod suddenly exits with the following error:

example-754b578d-listener listener 2024-01-09T06:12:25Z	INFO	listener-app.worker.kubernetesworker	Updating job info for the runner	{"runnerName": "example-6hcw5-runner-fb29k", REDACTED, "requestId": 6421142}
example-754b578d-listener listener 2024-01-09T06:12:25Z	INFO	listener-app.worker.kubernetesworker	Updating ephemeral runner with merge patch	{"json": "{\"status\":{\"jobDisplayName\":\"REDACTED\",\"workflowRunId\":7457087460}}"}
example-754b578d-listener listener 2024/01/09 06:12:25 Application returned an error: failed to handle job started: could not patch ephemeral runner status, patch JSON: {"status":{"jobDisplayName":"REDACTED","workflowRunId":7457087460}}, error: ephemeralrunners.actions.github.com "example-6hcw5-runner-fb29k" not found

After that, the listener pod gets into a crash loop with the following error:

example-754b578d-listener listener 2024-01-09T06:12:27Z	INFO	listener-app	app initialized
example-754b578d-listener listener 2024-01-09T06:12:27Z	INFO	listener-app	Starting metrics server
example-754b578d-listener listener 2024-01-09T06:12:27Z	INFO	listener-app	Starting listener
example-754b578d-listener listener 2024-01-09T06:12:27Z	INFO	listener-app	refreshing token	{"githubConfigUrl": "https://github.com/REDACTED"}
example-754b578d-listener listener 2024-01-09T06:12:27Z	INFO	listener-app	getting access token for GitHub App auth	{"accessTokenURL": "https://api.github.com/app/installations/REDACTED/access_tokens"}
example-754b578d-listener listener 2024-01-09T06:12:27Z	INFO	listener-app	getting runner registration token	{"registrationTokenURL": "https://api.github.com/repos/REDACTED/actions/runners/registration-token"}
example-754b578d-listener listener 2024-01-09T06:12:27Z	INFO	listener-app	getting Actions tenant URL and JWT	{"registrationURL": "https://api.github.com/actions/runner-registration"}
example-754b578d-listener listener 2024/01/09 06:12:28 Application returned an error: createSession failed: failed to create session: 409 - had issue communicating with Actions backend: The runner scale set example already has an active session for owner example-754b578d-listener.

It seems the listener exits at:

return fmt.Errorf("could not patch ephemeral runner status, patch JSON: %s, error: %w", string(mergePatch), err)

for _, jobStarted := range jobsStarted {
if err := handler.HandleJobStarted(ctx, jobStarted); err != nil {
return fmt.Errorf("failed to handle job started: %w", err)
}
}

Describe the expected behavior

It would be nice to keep a listener running even if a merge patch is failed.

Additional Context

-

Controller Logs

2024-01-09T06:04:04Z INFO EphemeralRunner Checking if runner exists in GitHub service {"ephemeralrunner": {"name":"example-6hcw5-runner-fb29k","namespace":"arc-runners"}, "runnerId": 6247604}
2024-01-09T06:04:04Z INFO EphemeralRunner Runner does not exist in GitHub service {"ephemeralrunner": {"name":"example-6hcw5-runner-fb29k","namespace":"arc-runners"}, "runnerId": 6247604}
2024-01-09T06:04:04Z INFO EphemeralRunner Ephemeral runner has finished since it does not exist in the service anymore {"ephemeralrunner": {"name":"example-6hcw5-runner-fb29k","namespace":"arc-runners"}}
2024-01-09T06:04:04Z INFO EphemeralRunner Updating ephemeral runner status to Finished {"ephemeralrunner": {"name":"example-6hcw5-runner-fb29k","namespace":"arc-runners"}}
2024-01-09T06:04:04Z INFO EphemeralRunner EphemeralRunner status is marked as Finished {"ephemeralrunner": {"name":"example-6hcw5-runner-fb29k","namespace":"arc-runners"}}
2024-01-09T06:04:04Z INFO EphemeralRunner EphemeralRunner has already finished. Stopping reconciliation and waiting for EphemeralRunnerSet to clean it up {"ephemeralrunner": {"name":"example-6hcw5-runner-fb29k","namespace":"arc-runners"}, "phase": "Succeeded"}
2024-01-09T06:04:04Z INFO EphemeralRunnerSet Deleting finished ephemeral runner {"ephemeralrunnerset": {"name":"example-6hcw5","namespace":"arc-runners"}, "name": "example-6hcw5-runner-fb29k"}
2024-01-09T06:04:04Z INFO EphemeralRunner Successfully removed runner registration finalizer {"ephemeralrunner": {"name":"example-6hcw5-runner-fb29k","namespace":"arc-runners"}}
2024-01-09T06:04:04Z INFO EphemeralRunner Finalizing ephemeral runner {"ephemeralrunner": {"name":"example-6hcw5-runner-fb29k","namespace":"arc-runners"}}
2024-01-09T06:04:04Z INFO EphemeralRunner Cleaning up the runner pod {"ephemeralrunner": {"name":"example-6hcw5-runner-fb29k","namespace":"arc-runners"}}
2024-01-09T06:04:04Z INFO EphemeralRunner Deleting the runner pod {"ephemeralrunner": {"name":"example-6hcw5-runner-fb29k","namespace":"arc-runners"}}
2024-01-09T06:04:04Z INFO EphemeralRunner Waiting for ephemeral runner owned resources to be deleted {"ephemeralrunner": {"name":"example-6hcw5-runner-fb29k","namespace":"arc-runners"}}
2024-01-09T06:04:04Z INFO EphemeralRunner Finalizing ephemeral runner {"ephemeralrunner": {"name":"example-6hcw5-runner-fb29k","namespace":"arc-runners"}}
2024-01-09T06:04:04Z INFO EphemeralRunner Cleaning up the runner pod {"ephemeralrunner": {"name":"example-6hcw5-runner-fb29k","namespace":"arc-runners"}}
2024-01-09T06:04:04Z INFO EphemeralRunner Waiting for ephemeral runner owned resources to be deleted {"ephemeralrunner": {"name":"example-6hcw5-runner-fb29k","namespace":"arc-runners"}}
2024-01-09T06:12:26Z	INFO	AutoscalingListener	Listener pod failed, deleting it and re-creating it	{"autoscalinglistener": {"name":"example-754b578d-listener","namespace":"arc-systems"}, "namespace": "arc-systems", "name": "example-754b578d-listener", "reason": "", "message": ""}"
2024-01-09T06:12:26Z	INFO	AutoscalingListener	Creating a listener pod	{"autoscalinglistener": {"name":"example-754b578d-listener","namespace":"arc-systems"}}"
2024-01-09T06:12:26Z	INFO	AutoscalingListener	Creating listener pod	{"autoscalinglistener": {"name":"example-754b578d-listener","namespace":"arc-systems"}, "namespace": "arc-systems", "name": "example-754b578d-listener"}"
2024-01-09T06:12:26Z	INFO	AutoscalingListener	Created listener pod	{"autoscalinglistener": {"name":"example-754b578d-listener","namespace":"arc-systems"}, "namespace": "arc-systems", "name": "example-754b578d-listener"}"
2024-01-09T06:12:30Z	INFO	AutoscalingListener	Listener pod failed, deleting it and re-creating it	{"autoscalinglistener": {"name":"example-754b578d-listener","namespace":"arc-systems"}, "namespace": "arc-systems", "name": "example-754b578d-listener", "reason": "", "message": ""}"
2024-01-09T06:12:30Z	INFO	AutoscalingListener	Creating a listener pod	{"autoscalinglistener": {"name":"example-754b578d-listener","namespace":"arc-systems"}}"
2024-01-09T06:12:30Z	INFO	AutoscalingListener	Creating listener pod	{"autoscalinglistener": {"name":"example-754b578d-listener","namespace":"arc-systems"}, "namespace": "arc-systems", "name": "example-754b578d-listener"}"
2024-01-09T06:12:30Z	INFO	AutoscalingListener	Created listener pod	{"autoscalinglistener": {"name":"example-754b578d-listener","namespace":"arc-systems"}, "namespace": "arc-systems", "name": "example-754b578d-listener"}"

Runner Pod Logs

-

Activity

  1. added
    bug
    gha-runner-scale-set
    needs triage
    on Jan 9, 2024
  2. changed the title [-]<Please write what didn't work for you here>[/-] [+]Listener gets into crash loop with createSession 409 error[/+] on Jan 9, 2024
  3. int128 commented on Jan 16, 2024

    @int128
    ContributorAuthor

    I have reverted the Helm chart to v0.7.0 and then the self-hosted runners seems stable.

    I noticed the below differences between v0.7.0 (githubrunnerscalesetlistener) and v0.8.0 (ghalistener). Could you check them?

    Error handling on updating an EphemeralRunner

    For v0.7.0 (githubrunnerscalesetlistener), it just writes an error log.

    err := s.kubeManager.UpdateEphemeralRunnerWithJobInfo(s.ctx, s.settings.Namespace, jobInfo.RunnerName, jobInfo.OwnerName, jobInfo.RepositoryName, jobInfo.JobWorkflowRef, jobInfo.JobDisplayName, jobInfo.WorkflowRunId, jobInfo.RunnerRequestId)
    if err != nil {
    s.logger.Error(err, "could not update ephemeral runner with job info", "runnerName", jobInfo.RunnerName, "requestId", jobInfo.RunnerRequestId)
    }

    For v0.8.0 (ghalistener), it returns the error and the listener process accidentally exits.

    if err := handler.HandleJobStarted(ctx, jobStarted); err != nil {
    return fmt.Errorf("failed to handle job started: %w", err)
    }

    I think it should handle the error to avoid crash loop.

    Graceful shutdown of Actions service session

    For v0.7.0 (githubrunnerscalesetlistener), it deletes the current session.


    func (m *AutoScalerClient) Close() error {
    m.logger.Info("closing.")
    return m.client.Close()
    }

    err := m.client.DeleteMessageSession(ctxWithTimeout, m.session.RunnerScaleSet.Id, m.session.SessionId)

    For v0.8.0 (ghalistener), it does not delete the session. I think it causes 409 errors.

  4. mumoshu commented on Jan 16, 2024

    @mumoshu
    Collaborator

    @nikola-jokic @Link- Hey! I think we found some regression in 0.8.0.

    I discussed offline with @int128, and I believe this is caused by the eventual consistency of data returned by GHA, which was handled gracefully in 0.7.0 but not in 0.8.0.

    Our theory:

    1. ephemeralrunnerset controller creates ephemeralrunner
    2. ephemeralrunner controller creates a runner pod
    3. Runner pod starts the agent, which starts the job and notifies the GHA API about the job start
    4. ephemeralrunner controller calls GHA service API to check existence of the runner in the service.
    5. GHA API says the runner is inexistent(although we did register it beforehand. Perhaps due to eventual consistency in your service), resulting in the controller to mark the ephemeralrunner as finished
    6. ephemeralrunnerset controller removes the ephemeralrunner as finished
    7. The listener gets the job started notification from the GHA service.
    8. The listener could not find the ephemeralrunner noted in the notification, existing with status 1.
    9. The listener is restated by k8s, failing instantly due to the duplicate GHA session as it has not been cleaned up in step 8

    We think the new ghalistener introduced in 0.8.0 has two regressions(would you mind confirming?) related to step 8, where:

    • It doesn't close the session on listener exit anymore in 0.8.0, leaving an unclosed session, which triggers duplicate session errors after the listener restarts.
      • In 0.7.0 runnerscalesetlistener we did use defer like
        // Create message listener
        autoScalerClient, err := NewAutoScalerClient(ctx, actionsServiceClient, &logger, rc.RunnerScaleSetId)
        if err != nil {
        return fmt.Errorf("failed to create a message listener: %w", err)
        }
        defer autoScalerClient.Close()
      • In 0.8.0, no session clean up in neither main or app:
        func (app *App) Run(ctx context.Context) error {
        var errs []error
        if app.worker == nil {
        errs = append(errs, fmt.Errorf("worker not initialized"))
        }
        if app.listener == nil {
        errs = append(errs, fmt.Errorf("listener not initialized"))
        }
        if err := errors.Join(errs...); err != nil {
        return fmt.Errorf("app not initialized: %w", err)
        }
        g, ctx := errgroup.WithContext(ctx)
        g.Go(func() error {
        app.logger.Info("Starting listener")
        return app.listener.Listen(ctx, app.worker)
        })
        if app.metrics != nil {
        g.Go(func() error {
        app.logger.Info("Starting metrics server")
        return app.metrics.ListenAndServe(ctx)
        })
        }
        return g.Wait()
        }
    • It fails immediately on the missing ephemeralrunner error in 0.8.0.

    @nikola-jokic @Link- If the above theory stands, can we at least fix the second bullet point so that the listener doesn't start failing immediately when the GHA service returns stale data?

    From @int128 and his colleagues' observation, the runner scale set example already has an active session for owner example-754b578d-listener error seems to persist for approx 10 minutes which delays the job runs for the runnerscaleset for that long, and this seems to happen quite often 🤔

  5. Link- commented on Jan 16, 2024

    @Link-
    Member

    @mumoshu @int128 thank you for your great work troubleshooting and reporting this issue. We will address it in a patch release, in the meantime, you don't have to revert to previous versions. We expected some problems to arise with the new listener so we included a fallback:

    Update the LISTENER_ENTRYPOINT to /github-runnerscaleset-listener in order to use older listener app.

    You can do it by updating the listener template:

  6. added
    priority-0
    on Jan 16, 2024
  7. mumoshu commented on Jan 16, 2024

    @mumoshu
    Collaborator

    @Link- Awesome! I missed that. Thank you for sharing and all your effort!

  8. TiagoJMartins commented on Jan 18, 2024

    @TiagoJMartins

    Update the LISTENER_ENTRYPOINT to github-runnerscaleset-listener in order to use older listener app.

    This definitely fixed it for me on 0.8.1, mentioned here. Hoping the next release will include the permanent fix 🤞🏻

    I was also having issues with high-usage runner sets getting into this crashing state, and that has also been resolved by changing the entrypoint.

  9. removed
    needs triage
    on Jan 22, 2024
  10. ahatzz11 commented on Jan 25, 2024

    @ahatzz11
    Contributor

    I hit this issue in our organization today and had a very hard time fixing it with the above suggestions, so I'm putting some information here to help others that might run into this until a proper fix is in place. We are running ~50 runners at max right now and have hundreds to thousands of individual jobs a day. If anything here below is wrong please let me know.


    Above @Link- mentioned that you should insert LISTENER_ENTRYPOINT with a value of github-runnerscaleset-listener in the listener template. I think there might be some confusion here because it seems this is the incorrect value to use and the incorrect location to put this env var. After attempting the proposed fix above I still encountered this patch issue and I noticed that the command didn't update for the listener pod. Here was a section of my values file for the gha-runner-scale-set helm chart:

    listenerTemplate:
      spec:
        containers:
          - name: listener
            securityContext:
              runAsUser: 1000
            env:
              - name: LISTENER_ENTRYPOINT
                value: github-runnerscaleset-listener

    Here is the kubectl pod describe:

    Containers:
      listener:
        Container ID:
        Image:         ghcr.io/actions/gha-runner-scale-set-controller:0.8.1
        Image ID:
        Port:          8080/TCP
        Host Port:     0/TCP
        Command:
          /ghalistener
        State:          Waiting
          Reason:       ContainerCreating
        Ready:          False
        Restart Count:  0
        Environment:
          LISTENER_CONFIG_PATH:  /etc/gha-listener/config.json
          LISTENER_ENTRYPOINT:   github-runnerscaleset-listener

    Notice here that the Command: /ghalistener is still pointing at the new listener. This solution from above does not seem to work.


    The solution I found to work here is to add an env var of LISTENER_ENTRYPOINT with the value of /github-runnerscaleset-listener to the values file for the gha-runner-scale-set-controller helm chart. Here is an example:

    replicaCount: 1
    labels: {}
    
    env: 
      - name: LISTENER_ENTRYPOINT
        value: /github-runnerscaleset-listener

    This changes the environment variable on the controller which then creates a listener that has the proper entrypoint. This can be seen with another kubectl describe pod on the listener:

    Containers:
      listener:
        Container ID:  containerd://c0baad31de660705d8abf992aaf3aae2357531e247a0e679dbe268b666136bc8
        Image:         ghcr.io/actions/gha-runner-scale-set-controller:0.8.1
        Image ID:      ghcr.io/actions/gha-runner-scale-set-controller@sha256:14f6df6f6300f34c4377b05e72378b05d813160556e3fd3415e56049d7b30ac2
        Port:          8080/TCP
        Host Port:     0/TCP
        Command:
          /github-runnerscaleset-listener
        State:          Running
          Started:      Wed, 24 Jan 2024 18:46:21 -0600
        Ready:          True
        Restart Count:  0
        Environment:
          LISTENER_CONFIG_PATH:  /etc/gha-listener/config.json

    Here's the code path I followed to get to this solution:

  11. Link- commented on Jan 25, 2024

    @Link-
    Member

    Sorry about that @ahatzz11 - you are right, I missed the / in my comment. I've edited it now to fix it. We're pushing a fix for this soon, stay tuned.

  12. ahatzz11 commented on Jan 25, 2024

    @ahatzz11
    Contributor

    @Link- Thanks for the update! I still think the original comment is incorrect though. It says to put it in the listenerTemplate: section of the values file for the gha-runner-scale-set chat, but it should actually live at the root level of the values file for the gha-runner-scale-set-controller chart.

    Super excited to see some fixes for these issues! Happy to do some testing in our environment when it is all ready to go.

  13. y-takebe commented on Mar 12, 2024

    @y-takebe

    Hi, there.

    I encountered a similar problem when using ARC at the Organization level, a restart loop for AutoscalingListener.

    The solution described by @ahatzz11, setting env in the helm chart of gha-runner-scale-set-controller, solved the restart loop.

    I spent 10 days to get to this page! 😵

    I think it should be in the official GitHub documentation or after adding the env setting to the chart to resolve it.

    Thanks!

  14. softlberton commented on Apr 16, 2024

    @softlberton

    I've been working with ARC for the last two days, yesterday I was able to install ARC without any problems using GitHub App authentication and it works fine.

    Today I'm doing the same, installing ARC using PAT authentication and I got this error:

    2024-04-16T08:29:55Z    INFO    listener-app    getting Actions tenant URL and JWT      {"registrationURL": "https://api.github.com/actions/runner-registration"} 2024/04/16 08:29:55 Application returned an error: createSession failed: failed to create session: 409 - had issue communicating with Actions backend: The runner scale set arc-runner-set already has an active session for owner arc-runner-set-754b578d-listener.

    Thanks @ahatzz11 for indicating the solution (workaround) for this problem, so I managed to solve this problem by installing arc-runner-set as follows:

    helm install arc-runner-set -n arc-runners \
     --create-namespace \
     --set githubConfigUrl="${GITHUB_CONFIG_URL}" \
     --set githubConfigSecret="pre-defined-secret" \
     --set env="LISTENER_ENTRYPOINT=github-runnerscaleset-listener" \                    # LISTENER_ENTRYPOINT env
     oci://ghcr.io/actions/actions-runner-controller-charts/gha-runner-scale-set

    ARC runner type: GitHub Org
    ARC runner version: 0.9.0

  15. nikola-jokic commented on Apr 16, 2024

    @nikola-jokic
    Collaborator

    Hey @softlberton,

    Can you please help me by writing down how to reproduce this problem? I'm struggling to replicate it and I would really like to get to the bottom of it, but I'm failing to reproduce it 😞

  16. softlberton commented on Apr 16, 2024

    @softlberton

    Hi @nikola-jokic,

    Ok, I'll see if I can reproduce this error again.

  17. joekhoobyar commented on Jul 1, 2024

    @joekhoobyar

    This is still happening for me.

  18. casey-robertson-paypal commented on Aug 28, 2024

    @casey-robertson-paypal

    Perhaps there is another failure mode or regression? We have only ever been on 0.8.3 of the controller chart and we are experiencing this with one of our listeners right now.

  19. luis02lopez commented on Nov 28, 2024

    @luis02lopez

    Ok, finally I got it working, thanks to @ahatzz11 for noticing that the change must be in the set-controller, not the set. I deploy my charts with Terraform.

    Important: After making the change, you'll need to uninstall/remove the charts and install it again, if not, the fail loop is still going to happen but every 10 minutes, full solution:

    resource "helm_release" "github_actions_runner_controller" {
      name             = "github-action-runners-controller"
      namespace        = "github-arc-systems-controller"
      repository       = "oci://ghcr.io/actions/actions-runner-controller-charts"
      chart            = "gha-runner-scale-set-controller"
      version          = "0.9.3"
      set {
        name  = "env[0].name"
        value = "LISTENER_ENTRYPOINT"
      }
      set {
        name  = "env[0].value"
        value = "/github-runnerscaleset-listener"
      }
      create_namespace = true
    }
    
    resource "helm_release" "github_actions_runner_set" {
      name       = "github-action-runners"
      namespace  = "github-arc-systems"
      repository = "oci://ghcr.io/actions/actions-runner-controller-charts"
      chart      = "gha-runner-scale-set"
      version    = "0.9.3"
      set {
        name  = "githubConfigUrl"
        value = "https://github.com/your-org"
      }
      set {
        name  = "githubConfigSecret"
        value = "the-name-of-your-secret"
      }
      ## Optional - tag you'll use in the actual pipeline, example 'runs-on: self-hosted-runner'
      set {
        name  = "runnerScaleSetName"
        value = "self-hosted-runner"
      }
      create_namespace = true
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

buggha-runner-scale-setpriority-0

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions