Commit Graph
42 Commits
Author SHA1 Message Date
c4770cde7c fix(error): detect READONLY errors from Lua scripts on read-only replicas (#3769)
When a Lua script containing a write command is executed against a
read-only replica in a Redis Cluster, the error may contain
"-READONLY You can't write against a read only replica" embedded
within a larger error message rather than starting with "READONLY ".

The existing code only checked for the "READONLY " prefix, missing
this format. This caused shouldRetry() and isReadOnlyError() to fail,
preventing automatic retry and connection pool cleanup.

The fix checks for the exact substring
"-READONLY You can't write against a read only replica" which is
specific enough to avoid false positives while catching the Lua
script error format.

Closes #2770

Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
2026-04-09 15:08:05 +03:00
LINKIWIandGitHub 2ba8388eed feat(error): Add typed error for NOSCRIPT replies from Redis (#3738) 2026-03-18 17:02:09 +02:00
ofekshenawaandGitHub 4edf494293 fix(retry): Add retry mechanism for NOREPLICAS error (#3647) 2025-12-10 18:14:05 +02:00
6c24f600de feat(errors): Introduce typed errors (#3602)
* typed errors

* add error documentation

* backwards compatibility

* update readme, remove Is methods

* Update internal/proto/redis_errors.go

Co-authored-by: Copilot <[email protected]>

* Update internal/proto/redis_errors.go

Co-authored-by: Copilot <[email protected]>

* support error wrapping for io and context errors

* use unwrapping of errors in push for consistency

* add common error types

* fix test

* fix flaky test

* add comments in the example

---------

Co-authored-by: Copilot <[email protected]>
2025-11-19 17:31:54 +02:00
a15e76394c fix(pool): Pool ReAuth should not interfere with handoff (#3547)
* fix(pool): wip, pool reauth should not interfere with handoff

* fix credListeners map

* fix race in tests

* better conn usable timeout

* add design decision comment

* few small improvements

* update marked as queued

* add Used to clarify the state of the conn

* rename test

* fix(test): fix flaky test

* lock inside the listeners collection

* address pr comments

* Update internal/auth/cred_listeners.go

Co-authored-by: Copilot <[email protected]>

* Update internal/pool/buffer_size_test.go

Co-authored-by: Copilot <[email protected]>

* wip refactor entraid

* fix maintnotif pool hook

* fix mocks

* fix nil listener

* sync and async reauth based on conn lifecycle

* be able to reject connection OnGet

* pass hooks so the tests can observe reauth

* give some time for the background to execute commands

* fix tests

* only async reauth

* Update internal/pool/pool.go

Co-authored-by: Copilot <[email protected]>

* Update internal/auth/streaming/pool_hook.go

Co-authored-by: Copilot <[email protected]>

* Update internal/pool/conn.go

Co-authored-by: Copilot <[email protected]>

* chore(redisotel): use metric.WithAttributeSet to avoid copy (#3552)

In order to improve performance replace `WithAttributes` with `WithAttributeSet`.
This avoids the slice allocation and copy that is done in `WithAttributes`.

For more information see https://github.com/open-telemetry/opentelemetry-go/blob/v1.38.0/metric/instrument.go#L357-L376

* chore(docs): explain why MaxRetries is disabled for ClusterClient (#3551)

Co-authored-by: Nedyalko Dyakov <[email protected]>

* exponential backoff

* address pr comments

* address pr comments

* remove rlock

* add some comments

* add comments

---------

Co-authored-by: Copilot <[email protected]>
Co-authored-by: Warnar Boekkooi <[email protected]>
Co-authored-by: Justin <[email protected]>
2025-10-22 12:45:30 +03:00
Nedyalko DyakovandGitHub 4c635cc563 fix(txpipeline): should return error on multi/exec on multiple slots [CAE-1028] (#3408)
* fix(txpipeline): should return error on multi/exec on multiple slots

* fix(txpipeline): test normal tx pipeline behaviour

* chore(err): Extract crossslot err and add test

* fix(txpipeline): short curcuit the tx if there are no commands

* chore(tests): validate keys are in different slots
2025-06-18 14:18:00 +03:00
LINKIWIandGitHub ba26e35a2c Export pool errors for public consumption (#3380) 2025-05-19 19:23:10 +03:00
694a7101d4 Make MASTERDOWN a retriable error in RedisCluster client (#3164)
When clusters are running with `replica-server-stale-data no`, replicas
will return a MASTERDOWN error under two conditions:
  1. The primary has failed and we are not serving requests.
  2. A replica has just started and has not yet synced from the primary.

The former, primary has failed and we are not serving requests, is
similar to a CLUSTERDOWN error and should be similarly retriable.

When a replica has just started and has not yet synced from the primary
the request should be retried on other available nodes in the shard.
Otherwise a percentage of the read requests to the shard will fail.

Examples when `replica-server-stale-data no` is enabled:
  1. In a cluster using `ReadOnly` with a single read replica, every
     read request will return errors to the client because MASTERDOWN is
     not a retriable error.
  2. In a cluster using `RouteRandomly` a percentage of the requests
     will return errors to the client based on if this server was
     selected.

Co-authored-by: Nedyalko Dyakov <[email protected]>
2025-03-24 15:28:20 +02:00
4f09082f6b fix: connection pool timeout, increase retries (#3298)
* fix: connection pool timeout, increase retries

Signed-off-by: monkey <[email protected]>

* fix: add shouldRetry test

Signed-off-by: monkey <[email protected]>

---------

Signed-off-by: monkey <[email protected]>
Co-authored-by: Nedyalko Dyakov <[email protected]>
2025-03-14 10:05:22 +02:00
162a15432b fix: Fixed issue with context cancelled error leading to connection spikes on Primary instances (#3190)
* fix: Fixed issue with context cancelled error leading to connection spikes on Master

* fix: Added tests

* fix: Updated tests

---------

Co-authored-by: Bhargav Dodla <[email protected]>
Co-authored-by: Nedyalko Dyakov <[email protected]>
2025-03-05 22:08:27 +02:00
b64d9deef3 Handle IPv6 in isMovedError (#2981)
* Handle IPv6 in isMovedError

* Simplify GetAddr

---------

Co-authored-by: Monkey <[email protected]>
2024-04-28 12:37:44 +08:00
81947daa8d Handle wrapped errors in scripter.Run (#2674)
* Handle wrapped errors in script

* test

* remove accidentially committed changes

---------

Co-authored-by: ofekshenawa <[email protected]>
2023-10-30 18:08:18 +02:00
Vladimir Mihailenco 97b491aace chore: update import path 2023-01-23 08:48:54 +02:00
Vladimir Mihailenco d3d8002e89 feat: add HasErrorPrefix 2022-11-17 16:18:04 +02:00
Vladimir Mihailenco a18fad5bd3 chore: v9 2022-06-04 17:42:06 +03:00
Vladimir Mihailenco 1980be0f9f chore: fix golangci-lint 2022-06-04 10:50:58 +03:00
Pau Freixes 96f53a0159 fix: format 2021-10-04 17:22:18 +02:00
Pau Freixes 7f7c181761 fix: add whitespace for avoid unlikely colisions 2021-10-04 15:53:57 +02:00
Pau FreixesandGitHub 98bb99ddc2 Fix Redis Cluster issue during roll outs of new nodes with same addr (#1914)
* fix: recycle connections in some Redis Cluster scenarios

This issue was surfaced in a Cloud Provider solution that used for
rolling out new nodes using the same address (hostname) of the nodes
that will be replaced in a Redis Cluster, while the former ones once
depromoted as Slaves would continue in service during some mintues
for redirecting traffic.

The solution basically identifies when the connection could be stale
since a MOVED response will be returned using the same address (hostname)
that is being used by the connection. At that moment we consider the
connection as no longer usable forcing to recycle the connection.
2021-10-04 13:10:42 +03:00
monkey 26373ef2f1 follow to golang-lint 1.40
Signed-off-by: monkey <[email protected]>
2021-05-13 10:33:38 +08:00
Vladimir Mihailenco 02ccf05ed0 Close the conn on context timeout 2020-12-06 11:14:07 +02:00
wziww e0aa8939c7 TRYAGAIN error should be retry 2020-11-12 17:47:04 +08:00
Vladimir Mihailenco 21a1f58caf Retry timeout and retryable error 2020-07-24 15:52:15 +03:00
Vladimir Mihailenco 4440575966 Merge branch 'v8' 2020-05-21 10:16:44 +03:00
Vladimir Mihailenco 07656a01bf Add redis.Error interface and export ErrClosed
Fixes https://github.com/go-redis/redis/issues/1295
Closes https://github.com/go-redis/redis/pull/1296
2020-05-21 09:24:54 +03:00
Vladimir Mihailenco 3dcb844106 Bump major version 2020-05-19 08:52:38 +03:00
Vladimir Mihailenco 7779accbea Use semantic import versioning 2019-08-08 14:29:44 +03:00
Vladimir Mihailenco 48224a399f Remove releaseConnStrict 2019-08-08 11:44:55 +03:00
Vladimir Mihailenco 2927e15b6b Retry BadConnError 2019-08-08 11:44:55 +03:00
Vladimir Mihailenco 4e9cea8876 Add proper SingleConnPool implementation 2019-08-03 17:31:28 +03:00
Dimitrij Denissenko 7d856c5595 Make proto/parser an internal package 2016-07-02 13:52:10 +01:00
Vladimir Mihailenco 30ce5ebd57 Cleanup error handling code. 2016-03-19 16:33:14 +02:00
Vladimir Mihailenco 46790aa060 Add race test for big vals. Copy connection to avoid race with PubSub. 2016-03-14 16:34:15 +02:00
Vladimir Mihailenco ad0739be99 Extract pool package. Add pool benchmark. 2016-03-12 10:52:13 +02:00
Vladimir Mihailenco 673e999431 Close connection on network timeout. 2016-03-09 14:36:14 +02:00
Vladimir Mihailenco 110e93a8e4 Simplify connection management with sticky connection pool. Fixes #260. 2016-03-01 14:12:25 +02:00
Vladimir Mihailenco ade3425870 multi: fix recovering from bad connection. 2015-11-14 14:44:16 +02:00
Vladimir Mihailenco 36fcbb1f94 Update readme for v3. 2015-05-23 14:43:49 +03:00
Vladimir Mihailenco 8c67e00efc Add auto-retry and MaxRetries option. Fixes #84. 2015-05-10 17:02:47 +03:00
Vladimir Mihailenco 99fe9114b1 Add ClusterPipeline. 2015-04-13 09:31:30 +03:00
Vladimir Mihailenco 94a31f499f Attempt to cleanup cluster logic. 2015-04-07 12:51:01 +03:00
Vladimir Mihailenco deb41df992 Don't remove connection from the pool on redis errors. 2014-06-18 15:55:49 +03:00