Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUSY Redis is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE. #141

Open
kanevbg opened this issue Jul 2, 2019 · 4 comments

Comments

@kanevbg
Copy link

kanevbg commented Jul 2, 2019

Here is an error which occurs when Redis is busy (with LUA enabled):
CredisException: Uncaught exception 'CredisException' with message 'BUSY Redis is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE.' in app/code/local/Credis/Client.php:1162

@colinmollenhour
Copy link
Owner

How do you suggest this error is handled?

@kanevbg
Copy link
Author

kanevbg commented Jul 3, 2019

I guess it should be treated as a kind of operational timeout and do retries based on configuration but I do not have full understanding of the issue because I had no time to examine.

@colinmollenhour
Copy link
Owner

I think retries would be reasonable. Please submit a PR if you so feel inclined. Thanks!

@IJOL
Copy link

IJOL commented Jul 29, 2024

We are running in this exact issue, and we end applying this patch


Subject: [PATCH] [UPD] Exportacion en xls
---
Index: Client.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/Client.php b/Client.php
--- a/Client.php	(revision f11a89fd068d3e5db0c2b5a9ba8663bc36162e95)
+++ b/Client.php	(date 1722245007668)
@@ -1226,9 +1226,26 @@
                     throw $e;
                 }
             } else {
-                $this->write_command($command);
-                $response = $this->read_reply($name);
-                $response = $this->decode_reply($name, $response, $trackedArgs);
+                $retryCount = 0;
+                $maxRetries = 5;
+
+                while ($retryCount < $maxRetries) {
+                    try {
+                        $this->write_command($command);
+                        $response = $this->read_reply($name);
+                        $response = $this->decode_reply($name, $response, $trackedArgs);
+                        break; // Exit loop if successful
+                    } catch (CredisException $e) {
+                        if (strpos($e->getMessage(), 'BUSY') === 0) {
+                            $retryCount++;
+                            if ($retryCount >= $maxRetries) {
+                                throw $e; // Rethrow exception after max retries
+                            }
+                        } else {
+                            throw $e; // Rethrow exception if message does not contain 'BUSY'
+                        }
+                    }
+                }
             }
 
             // Watch mode disables reconnect so error is thrown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants