Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Protect against connection reuse across forks
- Loading branch information
Showing
2 changed files
with
16 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -272,7 +272,18 @@ def ensure_connected | |
tries = 0 | ||
|
||
begin | ||
connect unless connected? | ||
if connected? | ||
if Process.pid != @pid | ||
raise InheritedError, <<-EOS.gsub(/(?:^|\n)\s*/, " ").strip | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
wjessop
|
||
Tried to use a connection from a child process without reconnecting. | ||
You need to reconnect to Redis after forking. | ||
EOS | ||
end | ||
else | ||
@pid = Process.pid | ||
connect | ||
end | ||
|
||
tries += 1 | ||
|
||
yield | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Seems like this would be better than the gsub (simpler, easier to read):
raise InheritedError, "Tried to use a connection from a child process without reconnecting. You need to reconnect to Redis after forking."