{"record":{"id":"371dd8e8b53f49f0","repo":"crowdsecurity/crowdsec","slug":"cannot-wait-for-consumer-deregistration-w","errorCode":null,"errorMessage":"cannot wait for consumer deregistration: %w","messagePattern":"cannot wait for consumer deregistration: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/acquisition/modules/kinesis/run.go","lineNumber":111,"sourceCode":"func (s *Source) DeregisterConsumer(ctx context.Context) error {\n\ts.logger.Debugf(\"Deregistering consumer %s if it exists\", s.Config.ConsumerName)\n\t_, err := s.kClient.DeregisterStreamConsumer(ctx, &kinesis.DeregisterStreamConsumerInput{\n\t\t\tConsumerName: aws.String(s.Config.ConsumerName),\n\t\t\tStreamARN:    aws.String(s.Config.StreamARN),\n\t\t})\n\n\tvar resourceNotFoundErr *kinTypes.ResourceNotFoundException\n\tif errors.As(err, &resourceNotFoundErr) {\n\t\treturn nil\n\t}\n\n\tif err != nil {\n\t\treturn fmt.Errorf(\"cannot deregister stream consumer: %w\", err)\n\t}\n\n\terr = s.WaitForConsumerDeregistration(ctx, s.Config.ConsumerName, s.Config.StreamARN)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"cannot wait for consumer deregistration: %w\", err)\n\t}\n\n\treturn nil\n}\n\nfunc (s *Source) WaitForConsumerRegistration(ctx context.Context, consumerARN string) error {\n\tmaxTries := s.Config.MaxRetries\n\tfor i := range maxTries {\n\t\tdescribeOutput, err := s.kClient.DescribeStreamConsumer(ctx, &kinesis.DescribeStreamConsumerInput{\n\t\t\t\tConsumerARN: aws.String(consumerARN),\n\t\t\t})\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"cannot describe stream consumer: %w\", err)\n\t\t}\n\n\t\tif describeOutput.ConsumerDescription.ConsumerStatus == \"ACTIVE\" {\n\t\t\ts.logger.Debugf(\"Consumer %s is active\", consumerARN)\n\t\t\treturn nil","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/acquisition/modules/kinesis/run.go#L93-L129","documentation":"Returned by DeregisterConsumer when the follow-up WaitForConsumerDeregistration poll (error 421/422) fails, after the DeregisterStreamConsumer call itself succeeded. It signals the deregistration could not be confirmed before EnhancedRead continues.","triggerScenarios":"DeregisterStreamConsumer returns 200, then the confirmation loop either errors (throttling, IAM, network — see 421) or times out still seeing the consumer (see 422).","commonSituations":"Slow consumer deletion on busy streams combined with a low max_retries; describe-permission missing so every poll fails.","solutions":["Increase `max_retries` to give deletion confirmation more time.","Ensure the IAM principal has `kinesis:DescribeStreamConsumer` so the confirmation polls can run.","Check the wrapped error to distinguish a polling failure (permissions/throttle) from a timeout, and act accordingly (see errors for run.go:84 and run.go:90).","Re-run acquisition later — deregistration is idempotent, so restarting is safe."],"exampleFix":"// before\nmax_retries: 3\n// after\nmax_retries: 15","handlingStrategy":"retry","validationCode":"// Pre-check permissions for the confirmation loop\naws iam simulate-principal-policy --policy-source-arn <role> --action-names kinesis:DescribeStreamConsumer kinesis:DeregisterStreamConsumer","typeGuard":null,"tryCatchPattern":"if err := src.DeregisterConsumer(ctx); err != nil {\n    logger.WithError(err).Warn(\"deregistration unconfirmed; safe to retry on next start\")\n    // fall through — deregistration is idempotent (ResourceNotFound short-circuit)\n}","preventionTips":["Treat deregistration as best-effort/idempotent at startup and shutdown.","Configure max_retries generously so confirmation polling completes.","Alert on repeated deregistration timeouts — indicates stuck AWS-side consumers."],"tags":["aws","kinesis","timeout"],"backgroundTag":"request-timeout","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}