Skip to content

CRITICAL: Instance record orphaned when enqueue fails after DB create #686

Description

@poyrazK

Why is this an issue?

In internal/core/services/instance.go:295-317, instance is created in DB first, then task enqueue fails. No cleanup of the orphaned DB record.

What is causing it?

if err := s.repo.Create(ctx, inst); err != nil {
    return nil, err
}

if err := s.taskQueue.Enqueue(ctx, "provision_queue", job); err != nil {
    return nil, errors.Wrap(errors.Internal, "failed to enqueue", err)
    // DB record orphaned - instance exists with STARTING status but no job
}

How can it be solved?

Add rollback on enqueue failure:

if err := s.taskQueue.Enqueue(...); err != nil {
    s.repo.Delete(ctx, inst.ID)  // Rollback DB record
    return nil, err
}

Category

  • Small
  • Medium
  • Large

Severity

  • Low
  • Medium
  • High
  • Critical

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions