Skip to content

Commit

Permalink
fix: race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
siyul-park committed Jul 22, 2024
1 parent cf2c489 commit a21bdfb
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pkg/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ func New(config Config) *Runtime {
// LookupByID retrieves a symbol by ID from the table or loads it from the store if not found.
func (r *Runtime) Load(ctx context.Context, specs ...spec.Spec) ([]*symbol.Symbol, error) {
for _, spec := range specs {
spec.SetNamespace(r.namespace)
if spec.GetNamespace() != r.namespace {
spec.SetNamespace(r.namespace)

Check warning on line 69 in pkg/runtime/runtime.go

View check run for this annotation

Codecov / codecov/patch

pkg/runtime/runtime.go#L69

Added line #L69 was not covered by tests
}
}

return r.loader.Load(ctx, specs...)
Expand All @@ -77,7 +79,9 @@ func (r *Runtime) Store(ctx context.Context, specs ...spec.Spec) ([]*symbol.Symb
if spec.GetID() == uuid.Nil {
spec.SetID(uuid.Must(uuid.NewV7()))

Check warning on line 80 in pkg/runtime/runtime.go

View check run for this annotation

Codecov / codecov/patch

pkg/runtime/runtime.go#L80

Added line #L80 was not covered by tests
}

Check notice on line 81 in pkg/runtime/runtime.go

View check run for this annotation

codefactor.io / CodeFactor

pkg/runtime/runtime.go#L81

If block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (indent-error-flow)
spec.SetNamespace(r.namespace)
if spec.GetNamespace() != r.namespace {
spec.SetNamespace(r.namespace)
}
}

exists := make(map[uuid.UUID]spec.Spec)
Expand Down Expand Up @@ -107,7 +111,9 @@ func (r *Runtime) Store(ctx context.Context, specs ...spec.Spec) ([]*symbol.Symb
// Delete removes a spec from the Runtime and returns whether it was successfully deleted.
func (r *Runtime) Delete(ctx context.Context, specs ...spec.Spec) (int, error) {
for _, spec := range specs {
spec.SetNamespace(r.namespace)
if spec.GetNamespace() != r.namespace {
spec.SetNamespace(r.namespace)

Check warning on line 115 in pkg/runtime/runtime.go

View check run for this annotation

Codecov / codecov/patch

pkg/runtime/runtime.go#L115

Added line #L115 was not covered by tests
}
}

specs, err := r.store.Load(ctx, specs...)
Expand Down

0 comments on commit a21bdfb

Please sign in to comment.