Skip to content

Race condition between Redis null-check and hgetall call #71

Description

@ANSHSINGH050404

Labels: bug, medium-priority

## Problem

In `src/index.ts:356`:

```ts
const cachedStep = redis ? await redis.hgetall(`step:${userFlow}:${step.description}`) : {};
The redis variable is null-checked at the start, but between that check and the hgetall call, Redis could disconnect (or the client could be reset). This is a classic TOCTOU (Time-of-Check-Time-of-Use) race.
If redis is non-null at line 356 but the connection drops by line 538:
await redis.hset(`step:${userFlow}:${step.description}`, cacheData);
the hset call throws an unhandled error, crashing the step execution.
Related
src/redis.ts:34-36resetRedis() sets client = null after disconnecting. If called mid-execution (e.g., during test teardown), the dangling reference causes a crash.
Suggested fix
Add try/catch around Redis calls in index.ts, or use a proxy that returns null on connection errors instead of throwing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions