# ERR Protocol error: invalid bulk length

- **ID:** `redis/err-protocol-bad-int`
- **Domain:** redis
- **Category:** protocol_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

The Redis server received a malformed RESP (Redis Serialization Protocol) message with an invalid bulk string length, often due to a network corruption or a buggy client implementation.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Redis 6.2.6 | active | — | — |
| Redis 7.0.11 | active | — | — |
| ioredis 5.3.2 | active | — | — |
| Jedis 4.3.1 | active | — | — |

## Workarounds

1. **Enable Redis connection pooling with health checks to automatically drop corrupted connections. Example in Node.js using ioredis: `const redis = new Redis({ maxRetriesPerRequest: 3, retryStrategy: (times) => Math.min(times * 50, 2000) });`** (80% success)
   ```
   Enable Redis connection pooling with health checks to automatically drop corrupted connections. Example in Node.js using ioredis: `const redis = new Redis({ maxRetriesPerRequest: 3, retryStrategy: (times) => Math.min(times * 50, 2000) });`
   ```
2. **Add a proxy or load balancer that validates RESP protocol before forwarding to Redis, such as using HAProxy with a custom TCP health check.** (70% success)
   ```
   Add a proxy or load balancer that validates RESP protocol before forwarding to Redis, such as using HAProxy with a custom TCP health check.
   ```
3. **Upgrade the client library to the latest version that includes better RESP parsing. For Java Jedis: `jedis.close(); jedis = new Jedis(host, port);` after catching the error.** (85% success)
   ```
   Upgrade the client library to the latest version that includes better RESP parsing. For Java Jedis: `jedis.close(); jedis = new Jedis(host, port);` after catching the error.
   ```

## Dead Ends

- **** — The error is about incoming data, not outgoing buffers. (95% fail)
- **** — TLS may add overhead but is not the cause of malformed bulk lengths. (80% fail)
