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

Disconnect the Redis socket on fatal shutdown #13

Merged
merged 1 commit into from
Oct 12, 2023

Conversation

kovshenin
Copy link
Contributor

A fatal error during socket read/write (such as a memory exhausted error) can result in a corrupted persistent socket for future PHP requests. This change explicitly disconnects the Redis socket on shutdown that happened with a fatal error.

The problem can be reproduced by enabling persistent connections, writing a large value to Redis:

$buffer = '';
for ( $i = 0; $i <= 1024 * 1024 * 32; $i++ ) {
	$buffer .= chr( rand( 65, 90 ) );
}
wp_cache_set( 'foo', $buffer );

Then attempting to read that value with a low enough memory limit:

ini_set( 'memory_limit', '4M' );
wp_cache_get_multiple( [ 'foo', 'bar', 'baz' ] );

This should cause a memory exhausted fatal error in predis/src/Connection/StreamConnection.php exiting the script but leaving the persistent socket in a connected state, which in subsequent requests leads to poisoning/corruption.

A fatal error during socket read/write (such as a memory exhausted
error) can result in a corrupted persistent socket for future PHP
requests. This change explicitly disconnects the Redis socket on
shutdown that happened with a fatal error.
Copy link

@mikelittle mikelittle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

Copy link

@owaincuvelier owaincuvelier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

letsagoooo

@kovshenin kovshenin merged commit ea2b632 into master Oct 12, 2023
@kovshenin kovshenin deleted the psocket-corrupted-fix branch October 13, 2023 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants