Skip to content

Fix unrecoverable connection state#3905

Merged
petyaslavova merged 6 commits intoredis:masterfrom
itssimon:fix-redis-error-buffer-closed
Jan 9, 2026
Merged

Fix unrecoverable connection state#3905
petyaslavova merged 6 commits intoredis:masterfrom
itssimon:fix-redis-error-buffer-closed

Conversation

@itssimon
Copy link
Contributor

@itssimon itssimon commented Jan 6, 2026

Description of change

Fixes #3904.

Pull Request check-list

Please make sure to review and check all of these items:

  • Do tests and lints pass with this change?
  • Do the CI tests pass with this change (enable it first in your forked repo and wait for the github action build to finish)?
  • Is the new or changed code fully tested?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • Is there an example added to the examples folder (if applicable)?

NOTE: these things are not required to open a PR and can be done
afterwards / while the PR is open.

@jit-ci
Copy link

jit-ci bot commented Jan 6, 2026

Hi, I’m Jit, a friendly security platform designed to help developers build secure applications from day zero with an MVS (Minimal viable security) mindset.

In case there are security findings, they will be communicated to you as a comment inside the PR.

Hope you’ll enjoy using Jit.

Questions? Comments? Want to learn more? Get in touch with us.

@petyaslavova
Copy link
Collaborator

Hi @itssimon, thank you for your contribution! We will review it soon.

async def can_read_destructive(self) -> bool:
if not self._connected:
raise RedisError("Buffer is closed.")
raise ConnectionError(SERVER_CLOSED_CONNECTION_ERROR)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that raising an OSError would be better here. This method is called in the AbstractConnection's can_read_destructive where OSError is caught and a ConnectionError is raised with additional info about the host and port.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. Updated.
Note that _AsyncHiredisParser raises ConnectionError for the same condition. Might want to update that too for consistency. Happy to do that in this PR as well.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@itssimon yeah, it will be great, thank you!
Just use this error only for the can_read_destructive method.
on_connect should still raise ConnectionError as it is used in a different type of context.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All done!

Copy link
Collaborator

@petyaslavova petyaslavova left a comment

Choose a reason for hiding this comment

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

LGTM.

@petyaslavova petyaslavova merged commit 12fbc7d into redis:master Jan 9, 2026
72 of 73 checks passed
@itssimon itssimon deleted the fix-redis-error-buffer-closed branch January 9, 2026 11:22
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.

Unrecoverable connection state where parser raises RedisError("Buffer is closed.")

2 participants