Sitelet https://github.com/predis/predis/pull/1731
Skip to content

Fix infinite loop when the connection closes partway through a bulk reply - #1731

Open
NotAFlightRisk wants to merge 2 commits into
predis:mainfrom
NotAFlightRisk:fix/bulk-reply-eof-loop
Open

NotAFlightRisk wants to merge 2 commits into
predis:mainfrom
NotAFlightRisk:fix/bulk-reply-eof-loop

Conversation

@NotAFlightRisk

Copy link
Copy Markdown

fread() gives back an empty string at EOF rather than false, so when the connection closes partway through a bulk reply, predis keeps waiting for bytes it'll never recieve and pegs a core until you kill it. read_write_timeout doesn't help because every read returns straight away.

You don't need anything exotic to hit it. A pubsub subscriber that falls behind gets cut off by Redis's default client-output-buffer-limit pubsub 32mb 8mb 60, and when the cut lands in middle of a message the subscriber on 3.6.1 just spins. Killing Redis during a big GET does the same.

Both connection classes had the same loop, so both now throw the usual ConnectionException when a read comes back empty at EOF, same as a close between replies already does. The tests are most of the diff, the fix itself is a few lines in each class.

Comment thread src/Connection/CompositeStreamConnection.php Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants