Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix for lost connection infinite loop #77

Merged
merged 6 commits into from

3 participants

@atorres757

Added the ability to retry establishing a connection to redis when the connection is lost. I also placed a sleep for 1 second before attempting to re-establish a connection. Our error logs were logging large amounts of the following error fwrite(): send of 51 bytes failed with errno=32 Broken pipe.

Allen Torres added some commits
Allen Torres Updated recreate method in Resque_Job class to set arguments in the s…
…ame fashion as getAruments returns them.
3955bc8
Allen Torres Added a check to see if we have args before we attempt to access the …
…first item in the payload args to prevent an undefined index error.
f6334bb
Allen Torres Updated Redisent.php to attempt three reconnects to the redis server …
…before giving up. Also supressed fwrite errors.
e4f39a6
@kalmas

Peer Reviewed. Looks good.

@chrisboulton

Awesome, thanks :thumbsup:.

I actually fixed this a little differently here a while ago but haven't merged back my changes from our customisations. (:disappointed:)

Anyway, more than happy to bring this across and in. Thanks again!

@chrisboulton chrisboulton merged commit 5fdc360 into chrisboulton:master
@atorres757

No prob, glad to help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 1, 2012
  1. Updated recreate method in Resque_Job class to set arguments in the s…

    Allen Torres authored
    …ame fashion as getAruments returns them.
  2. Added a check to see if we have args before we attempt to access the …

    Allen Torres authored
    …first item in the payload args to prevent an undefined index error.
Commits on Dec 28, 2012
  1. Updated Redisent.php to attempt three reconnects to the redis server …

    Allen Torres authored
    …before giving up. Also supressed fwrite errors.
  2. Reverted changes made to upstream master.

    Allen Torres authored
  3. Reverted changes made from upstream master.

    Allen Torres authored
This page is out of date. Refresh to see the latest.
Showing with 18 additions and 3 deletions.
  1. +18 −3 lib/Redisent/Redisent.php
View
21 lib/Redisent/Redisent.php
@@ -43,6 +43,13 @@ class Redisent {
* @access public
*/
public $port;
+
+ /**
+ * Number of times to attempt a reconnect
+ *
+ * @var int
+ */
+ public $max_reconnects = 3;
/**
* Creates a Redisent connection to the Redis server on host {@link $host} and port {@link $port}.
@@ -73,10 +80,18 @@ function __call($name, $args) {
$command = sprintf('*%d%s%s%s', count($args), CRLF, implode(array_map(array($this, 'formatArgument'), $args), CRLF), CRLF);
/* Open a Redis connection and execute the command */
+ $reconnects = 0;
for ($written = 0; $written < strlen($command); $written += $fwrite) {
- $fwrite = fwrite($this->__sock, substr($command, $written));
- if ($fwrite === FALSE) {
- throw new Exception('Failed to write entire command to stream');
+ $fwrite = @fwrite($this->__sock, substr($command, $written));
+ if ($fwrite === FALSE || $fwrite === 0) {
+ if ($reconnects >= (int)$this->max_reconnects) {
+ throw new Exception('Failed to write entire command to stream');
+ }else{
+ fclose($this->__sock);
+ sleep(1);
+ $this->establishConnection();
+ $reconnects++;
+ }
}
}
Something went wrong with that request. Please try again.