Skip to content

Commit

Permalink
fix(redis): Ignore context cancellation from the outside to avoid sid…
Browse files Browse the repository at this point in the history
…e effects during redis calls (#35)

* chore: drop obsolete golangcilint config
  • Loading branch information
carstendietrich authored Apr 10, 2024
1 parent 5afdc3a commit b44438a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 16 deletions.
12 changes: 0 additions & 12 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,11 @@ run:
concurrency: 4
timeout: 5m
tests: true
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs-use-default: true
modules-download-mode: readonly
allow-parallel-runners: false
go: '1.19'

# output configuration options
output:
# Format: colored-line-number|line-number|json|tab|checkstyle|code-climate|junit-xml|github-actions
#
# Multiple can be specified by separating them by comma, output can be provided
# for each of them by separating format name and path by colon symbol.
# Output path can be either `stdout`, `stderr` or path to the file to write to.
# Example: "checkstyle:report.json,colored-line-number"
#
# Default: colored-line-number
format: colored-line-number
print-issued-lines: true
print-linter-name: true
uniq-by-line: true
Expand Down
8 changes: 4 additions & 4 deletions cart/redis/infrastructure/redisStorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (r *RedisStorage) Inject(

// GetCart fetches a cart from redis and deserializes it
func (r *RedisStorage) GetCart(ctx context.Context, id string) (*cartDomain.Cart, error) {
cmd := r.client.Get(ctx, r.keyPrefix+id)
cmd := r.client.Get(context.WithoutCancel(ctx), r.keyPrefix+id)
if err := cmd.Err(); err != nil {
return nil, fmt.Errorf("could not get cart: %w", err)
}
Expand All @@ -130,7 +130,7 @@ func (r *RedisStorage) GetCart(ctx context.Context, id string) (*cartDomain.Cart

// HasCart checks if the cart id exists as a key in redis
func (r *RedisStorage) HasCart(ctx context.Context, id string) bool {
cmd := r.client.Exists(ctx, r.keyPrefix+id)
cmd := r.client.Exists(context.WithoutCancel(ctx), r.keyPrefix+id)
if err := cmd.Err(); err != nil {
r.logger.WithContext(ctx).WithField(flamingo.LogKeyModule, "RedisStorage").Warn(fmt.Errorf("HasCart: couldn't check redis exists: %w returned value: %q", err, cmd.Val()))

Expand All @@ -151,7 +151,7 @@ func (r *RedisStorage) StoreCart(ctx context.Context, cart *cartDomain.Cart) err
return fmt.Errorf("could not store cart: %w", err)
}

err = r.client.Set(ctx, r.keyPrefix+cart.ID, b, r.ttl(cart)).Err()
err = r.client.Set(context.WithoutCancel(ctx), r.keyPrefix+cart.ID, b, r.ttl(cart)).Err()
if err != nil {
return fmt.Errorf("could not store cart: %w", err)
}
Expand All @@ -174,7 +174,7 @@ func (r *RedisStorage) RemoveCart(ctx context.Context, cart *cartDomain.Cart) er
return ErrCartIsNil
}

err := r.client.Del(ctx, r.keyPrefix+cart.ID).Err()
err := r.client.Del(context.WithoutCancel(ctx), r.keyPrefix+cart.ID).Err()
if err != nil {
return fmt.Errorf("could not remove cart: %w", err)
}
Expand Down

0 comments on commit b44438a

Please sign in to comment.