Skip to content

Failed to create/update revision with error already exists  #8675

Closed

Description

@cdlliuy

/area API
Knative version 0.13.0, but I think the same issue may happens on the latest code base as well. I think it is a race condition issue.

Problem description:

In our repeatedly continuous test, we found sometimes kn client returned with revision already exists error, i.e.

2020-07-17 00:38:04.00 (UTC)]> kn service create e2e-test-1-knservice-05fe854b --image <image>  --wait-timeout 295 --env TARGET=revision1 
Creating service 'e2e-test-1-knservice-05fe854b' in namespace '1718b655-9c69':

  1.092s The Route is still working to reflect the latest desired specification.
  2.066s Revision creation failed with message: revisions.serving.knative.dev "e2e-test-1-knservice-05fe854b-znmzq-1" already exists.
  2.469s ...
  2.470s Configuration "e2e-test-1-knservice-05fe854b" is waiting for a Revision to become ready.
RevisionFailed: Revision creation failed with message: revisions.serving.knative.dev "e2e-test-1-knservice-05fe854b-znmzq-1" already exists.

The kn cmd above returned very quickly, the total execution duration is 4.38s.

Once the error happened, we checked the related configuration/revision info, I noticed the revision was just created with generation 1.

+ kn -n 1718b655-9c69 revision list -s e2e-test-1-knservice-05fe854b
NAME                                    SERVICE                                TRAFFIC   TAGS   GENERATION   AGE   CONDITIONS   READY     REASON
e2e-test-1-knservice-05fe854b-znmzq-1   e2e-test-1-knservice-05fe854b                    1            6s    0 OK / 4     Unknown   Deploying

The configuration CR:

apiVersion: v1
items:
- apiVersion: serving.knative.dev/v1
  kind: Configuration
  metadata:
    creationTimestamp: "2020-07-17T00:38:04Z"
    generation: 1
    .....
  spec:
    template:
      metadata:
        annotations:
          client.knative.dev/user-image: <image>
        creationTimestamp: null
        name: e2e-test-1-knservice-05fe854b-znmzq-1
      spec:
        containerConcurrency: 0
        containers:
        - env:
          - name: TARGET
            value: revision1
          image: <image>
          name: user-container
          readinessProbe:
            successThreshold: 1
            tcpSocket:
              port: 0
          resources: {}
        timeoutSeconds: 300
  status:
    conditions:
    - lastTransitionTime: "2020-07-17T00:37:33Z"
      status: Unknown
      type: Ready
    latestCreatedRevisionName: e2e-test-1-knservice-05fe854b-znmzq-1
    observedGeneration: 1

The revision CR:

apiVersion: v1
items:
- apiVersion: serving.knative.dev/v1
  kind: Revision
  metadata:
    name: e2e-test-1-knservice-05fe854b-znmzq-1
    ownerReferences:
    - apiVersion: serving.knative.dev/v1
      blockOwnerDeletion: true
      controller: true
      kind: Configuration
      name: e2e-test-1-knservice-05fe854b
      uid: 4e2b1eea-961c-4fc2-9378-9c44fb107b2e
      ......
  spec:
    containerConcurrency: 0
    containers:
    - env:
      - name: TARGET
        value: revision1
      image: <image>
      name: user-container
      readinessProbe:
        successThreshold: 1
        tcpSocket:
          port: 0
      resources: {}
    timeoutSeconds: 300
  status:
    conditions:
    - lastTransitionTime: "2020-07-17T00:37:35Z"
      message: Requests to the target are being buffered as resources are provisioned.
      reason: Queued
      severity: Info
      status: Unknown
      type: Active
    - lastTransitionTime: "2020-07-17T00:37:34Z"
      reason: Deploying
      status: Unknown
      type: ContainerHealthy
    - lastTransitionTime: "2020-07-17T00:37:34Z"
      reason: Deploying
      status: Unknown
      type: Ready
    - lastTransitionTime: "2020-07-17T00:37:34Z"
      reason: Deploying
      status: Unknown
      type: ResourcesAvailable
  • Logs of the errors:

First of all, a revision is just created by configuration controller on Jul 17 08:38:04

Jul 17 08:38:04 controller-6d4fc9997-cs5rz controller info {"level":"info","ts":"2020-07-17T00:37:32.125Z","logger":"controller.configuration-controller.event-broadcaster","caller":"record/event.go:274","msg":"Event(v1.ObjectReference{Kind:\"Configuration\", Namespace:\"1718b655-9c69\", Name:\"e2e-test-1-knservice-05fe854b\", UID:\"4e2b1eea-961c-4fc2-9378-9c44fb107b2e\", APIVersion:\"serving.knative.dev/v1\", ResourceVersion:\"103455296\", FieldPath:\"\"}): type: 'Normal' reason: 'Created' Created Revision \"e2e-test-1-knservice-05fe854b-znmzq-1\"","commit":"5a00846","knative.dev/controller":"configuration-controller"}

Jul 17 08:38:04 controller-6d4fc9997-cs5rz controller info {"level":"info","ts":"2020-07-17T00:37:32.225Z","logger":"controller.configuration-controller","caller":"controller/controller.go:403","msg":"Reconcile succeeded. Time taken: 258.323511ms.","commit":"5a00846","knative.dev/controller":"configuration-controller","knative.dev/traceid":"d6fe8444-5a92-45f9-994c-d85b047c02a2","knative.dev/key":"1718b655-9c69/e2e-test-1-knservice-05fe854b"}

Then, in another reconcile , a failure is reported.

Jul 17 08:38:05 controller-6d4fc9997-cs5rz controller info {"level":"info","ts":"2020-07-17T00:37:32.685Z","logger":"controller.configuration-controller.event-broadcaster","caller":"record/event.go:274","msg":"Event(v1.ObjectReference{Kind:\"Configuration\", Namespace:\"1718b655-9c69\", Name:\"e2e-test-1-knservice-05fe854b\", UID:\"4e2b1eea-961c-4fc2-9378-9c44fb107b2e\", APIVersion:\"serving.knative.dev/v1\", ResourceVersion:\"103455301\", FieldPath:\"\"}): type: 'Warning' reason: 'CreationFailed' Failed to create Revision: revisions.serving.knative.dev \"e2e-test-1-knservice-05fe854b-znmzq-1\" already exists","commit":"5a00846","knative.dev/controller":"configuration-controller"}

Jul 17 08:38:05 controller-6d4fc9997-cs5rz controller error {"level":"error","ts":"2020-07-17T00:37:33.041Z","logger":"controller.configuration-controller","caller":"configuration/reconciler.go:190","msg":"returned an error","commit":"5a00846","knative.dev/controller":"configuration-controller","knative.dev/traceid":"afbf1f2f-4b9d-4587-a453-fdea5b7fd0ac","knative.dev/key":"1718b655-9c69/e2e-test-1-knservice-05fe854b","targetMethod":"ReconcileKind","error":"failed to create Revision: revisions.serving.knative.dev \"e2e-test-1-knservice-05fe854b-znmzq-1\" already exists","stacktrace":"knative.dev/serving/pkg/client/injection/reconciler/serving/v1/configuration.(*reconcilerImpl).Reconcile\n\tknative.dev/serving/pkg/client/injection/reconciler/serving/v1/configuration/reconciler.go:190\nknative.dev/serving/vendor/knative.dev/pkg/controller.(*Impl).processNextWorkItem\n\tknative.dev/serving/vendor/knative.dev/pkg/controller/controller.go:394\nknative.dev/serving/vendor/knative.dev/pkg/controller.(*Impl).Run.func2\n\tknative.dev/serving/vendor/knative.dev/pkg/controller/controller.go:343"}

Jul 17 08:38:05 controller-6d4fc9997-cs5rz controller error {"level":"error","ts":"2020-07-17T00:37:33.041Z","logger":"controller.configuration-controller","caller":"controller/controller.go:409","msg":"Reconcile error","commit":"5a00846","knative.dev/controller":"configuration-controller","error":"failed to create Revision: revisions.serving.knative.dev \"e2e-test-1-knservice-05fe854b-znmzq-1\" already exists","stacktrace":"knative.dev/serving/vendor/knative.dev/pkg/controller.(*Impl).handleErr\n\tknative.dev/serving/vendor/knative.dev/pkg/controller/controller.go:409\nknative.dev/serving/vendor/knative.dev/pkg/controller.(*Impl).processNextWorkItem\n\tknative.dev/serving/vendor/knative.dev/pkg/controller/controller.go:395\nknative.dev/serving/vendor/knative.dev/pkg/controller.(*Impl).Run.func2\n\tknative.dev/serving/vendor/knative.dev/pkg/controller/controller.go:343"}

Problem Analysis

I think the problem is a race condition.

The configuration controller is responsible to create a revision, then it watches the revision as well.
So, when the newly added revision update comes in, the 2nd reconcile begins. I guess in some particular situation, if the cache of lister is not refreshed in time, the configuration controller thought it is a conflict.

Anyway, I can't determine which if statement is met when the conflict error is detected.

} else if !metav1.IsControlledBy(rev, config) {

if !equality.Semantic.DeepEqual(config.Spec.GetTemplate().Spec, rev.Spec) {

Any idea? ^^

Then, with below codes
https://github.com/knative/serving/blob/master/pkg/reconciler/configuration/configuration.go#L70-L75

Configuration is set to false with already exist error

Then, kn client stops its watch whenever the condition is false ..
https://github.com/knative/client/blob/217a8133446acfadd19600a768b2be52fb7afd19/pkg/wait/wait_for_ready.go#L201-L209

How to resolve?

  1. Any idea how to remove the race condition to detect the naming conflict?

  2. Even if the race happens, if configuration controlller doesn't mark its condition to false, then the error won't be seen at all , since the other reconcile will happen. But we do wish to detect the naming conflict error , how to balance?

  3. Any other possible solution?

Activity

  1. added
    kind/bug
    on Jul 17, 2020
  2. markusthoemmes commented on Jul 17, 2020

    @markusthoemmes
    Contributor

    Hmm, good analysis.

    In theory the listers shouldn't race because it's the same process updating everything since we run them all using the same informers.

    It would certainly be valuable to get to know which of the two if branches you mentioned are used. It shouldn't be the IsControlledBy check I believe as that'd just be completely broken. If it's the unequal Spec branch, I'm wondering what the diff actually looks like.

    Does this fix itself without using the kn client or is the service stuck being broken? Reproducing it on HEAD would be great too.

  3. cdlliuy commented on Jul 20, 2020

    @cdlliuy
    Author

    @markusthoemmes , the reconcile finally made the ksvc works, since the revision is finally ready, then the configuration got the other chances to trigger reconcile and so on ..

    As I explained , kn got error just because it stops watching when the configuration/ ksvc a condition is set to false.
    https://github.com/knative/client/blob/217a8133446acfadd19600a768b2be52fb7afd19/pkg/wait/wait_for_ready.go#L201-L209

    It is hard to judge which branch is used .. I guess we need to add some additional logs to understand more .. Anyway, these errors only observed in continuous test on our official environments which means we can't apply private change on that. So maybe adding a part of error log in these two branches in knative repo will help to identify the reason in the future.

  4. mattmoor commented on Jul 20, 2020

    @mattmoor
    Contributor

    If it's the unequal Spec branch, I'm wondering what the diff actually looks like.

    Yeah, +1. Is it defaulting?

    I guess we need to add some additional logs to understand more

    Should be fine to add more Debugf, which is how we run e2e tests.

  5. cdlliuy commented on Jul 31, 2020

    @cdlliuy
    Author

    raised a simple PR to add debug info for this, and I am not sure whether using similar code to https://github.com/knative/serving/blob/master/pkg/reconciler/route/route.go#L287-L313 will help to mitigate the race condition?
    @markusthoemmes @mattmoor ?

  6. github-actions commented on Oct 30, 2020

    @github-actions

    This issue is stale because it has been open for 90 days with no
    activity. It will automatically close after 30 more days of
    inactivity. Reopen the issue with /reopen. Mark the issue as
    fresh by adding the comment /remove-lifecycle stale.

  7. added
    lifecycle/stale
    on Oct 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/buglifecycle/stale

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions