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

Fix issue with pack_commands returning an empty byte sequence #2416

Merged
merged 2 commits into from Feb 7, 2023

Conversation

jmcbailey
Copy link
Contributor

Pull Request check-list

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

  • Does $ tox pass with this change (including linting)?
  • 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)?
  • Was the change added to CHANGES file?

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

Description of change

Under certain circumstances pack_commands() adds an empty byte sequence (b"") to the returned list, which when connecting to a Redis server over SSL could cause an EOF error:

redis.exceptions.ConnectionError: Error while reading from socket: (8, 'EOF occurred in violation of protocol (_ssl.c:2483)')

In our case we are running an async Falcon application using the uvicorn worker type; we ran into the problem when using a Redis pipeline to perform an MSET followed by one or more EXPIRE commands. The values in the MSET are images, generally around 5 to 6kb in size. From what I can see it was certain images within a very specific size range, where the length
of the value was just under 6000, that caused the problem (6000 being the buffer_cutoff value used in pack_commands).

(Note that in some/many cases the b"" doesn't seem to cause a problem; I wrote a simple script to reproduce the error, executing the code in the standard asyncio event loop, but couldn't reproduce it that way. It was only by creating a simple Falcon/uvicorn app and executing it within that that I could reproduce it; I guess it's to do with the fact that uvicorn uses uvloop instead of the asyncio event loop, and there must be some difference in the underlying SSL transport.)

@chayim
Copy link
Contributor

chayim commented Oct 20, 2022

@jmcbailey Can you think of a test that can help us reproduce this?

@chayim chayim added the bug Bug label Oct 20, 2022
@jmcbailey
Copy link
Contributor Author

@jmcbailey Can you think of a test that can help us reproduce this?

@chayim I can certainly add a unit test for the method(s) to cover this scenario. Adding a test to reproduce the SSL error would be trickier...

@chayim
Copy link
Contributor

chayim commented Oct 27, 2022

@jmcbailey Does this only occur with SSL? I'm happy to forgo the SSL side if they can be isolated.

@dvora-h can you help @jmcbailey out here?

@codecov-commenter
Copy link

codecov-commenter commented Jan 25, 2023

Codecov Report

Base: 92.28% // Head: 78.16% // Decreases project coverage by -14.13% ⚠️

Coverage data is based on head (fc84e75) compared to base (e7306aa).
Patch coverage: 100.00% of modified lines in pull request are covered.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@             Coverage Diff             @@
##           master    #2416       +/-   ##
===========================================
- Coverage   92.28%   78.16%   -14.13%     
===========================================
  Files         115      115               
  Lines       29734    29736        +2     
===========================================
- Hits        27440    23242     -4198     
- Misses       2294     6494     +4200     
Impacted Files Coverage Δ
redis/asyncio/connection.py 80.72% <100.00%> (-6.90%) ⬇️
redis/connection.py 78.22% <100.00%> (-8.54%) ⬇️
tests/test_asyncio/test_cluster.py 18.51% <0.00%> (-79.10%) ⬇️
tests/test_cluster.py 18.00% <0.00%> (-78.76%) ⬇️
redis/asyncio/cluster.py 16.96% <0.00%> (-74.72%) ⬇️
redis/cluster.py 18.77% <0.00%> (-71.66%) ⬇️
redis/asyncio/parser.py 17.30% <0.00%> (-63.47%) ⬇️
redis/commands/cluster.py 36.95% <0.00%> (-57.07%) ⬇️
redis/crc.py 45.45% <0.00%> (-54.55%) ⬇️
tests/mocks.py 68.96% <0.00%> (-27.59%) ⬇️
... and 33 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@dvora-h dvora-h merged commit f517287 into redis:master Feb 7, 2023
chayim pushed a commit that referenced this pull request Aug 31, 2023
Co-authored-by: Viktor Ivanov <viktor@infogrid.io>
Co-authored-by: Sergey Prokazov <sergey.prokazov@redis.com>
Co-authored-by: Anuragkillswitch <70265851+Anuragkillswitch@users.noreply.github.com>
Co-authored-by: dvora-h <67596500+dvora-h@users.noreply.github.com>
Co-authored-by: Alex Schmitz <aschmitz@box.com>
Co-authored-by: Alex Schmitz <alex.schmitz@gmail.com>
Co-authored-by: Chayim <chayim@users.noreply.github.com>
Co-authored-by: Bar Shaul <88437685+barshaul@users.noreply.github.com>
Co-authored-by: CrimsonGlory <CrimsonGlory@users.noreply.github.com>
Co-authored-by: Raymond Yin <raymond@tryevergreen.com>
Co-authored-by: zach.lee <zach.lee@sendbird.com>
Co-authored-by: James R T <jamestiotio@gmail.com>
Co-authored-by: dvora-h <dvora.heller@redis.com>
Co-authored-by: Marc Schöchlin <marc.schoechlin@flipapp.de>
Co-authored-by: Nick Gerow <nick.gerow@enlightedinc.com>
Co-authored-by: Igor Malinovskiy <u.glide@gmail.com>
Co-authored-by: Chayim I. Kirshen <c@kirshen.com>
Co-authored-by: Leibale Eidelman <me@leibale.com>
Co-authored-by: Thiago Bellini Ribeiro <hackedbellini@gmail.com>
Co-authored-by: woutdenolf <woutdenolf@users.sf.net>
Co-authored-by: shacharPash <93581407+shacharPash@users.noreply.github.com>
Co-authored-by: Mirek Długosz <miniopl+github@gmail.com>
Co-authored-by: Oran Avraham <252748+oranav@users.noreply.github.com>
Co-authored-by: mzdehbashi-github <85902780+mzdehbashi-github@users.noreply.github.com>
Co-authored-by: Tyler Hutcherson <tyler.hutcherson@redis.com>
Co-authored-by: Felipe Machado <462154+felipou@users.noreply.github.com>
Co-authored-by: AYMEN Mohammed <53928879+AYMENJD@users.noreply.github.com>
Co-authored-by: Marc Schöchlin <ms-github@256bit.org>
Co-authored-by: Avasam <samuel.06@hotmail.com>
Co-authored-by: Markus Gerstel <2102431+Anthchirp@users.noreply.github.com>
Co-authored-by: Kristján Valur Jónsson <sweskman@gmail.com>
Co-authored-by: Nick Gerow <Nick.G.123@hotmail.com>
Co-authored-by: Cristian Matache <cristianmatache@hotmail.com>
Co-authored-by: Anurag Bandyopadhyay <angbpy@gmail.com>
Co-authored-by: Seongchuel Ahn <aciddust20@gmail.com>
Co-authored-by: Alibi <aliby.bbb@gmail.com>
Co-authored-by: Smit Parmar <smitraj333@gmail.com>
Co-authored-by: Brad MacPhee <macphee@gmail.com>
Co-authored-by: Shahar Lev <shahar_lev@hotmail.com>
Co-authored-by: Vladimir Mihailenco <vladimir.webdev@gmail.com>
Co-authored-by: Kevin James <KevinJames@thekev.in>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: David Pacsuta <34983281+ant1fact@users.noreply.github.com>
Co-authored-by: Rich Bowen <rbowen@rcbowen.com>
Co-authored-by: gmbnomis <gmbnomis@users.noreply.github.com>
Co-authored-by: Vivanov98 <66319645+Vivanov98@users.noreply.github.com>
Co-authored-by: Kosuke <kosuke.zhang@gmail.com>
Co-authored-by: Sergey Prokazov <prokazov@users.noreply.github.com>
Co-authored-by: jmcbailey <jmcbailey@gmail.com>
Co-authored-by: Galtozzy <14139502+Galtozzy@users.noreply.github.com>
Co-authored-by: Abhishek Kumar Sinha <aksinha334@gmail.com>
Co-authored-by: Eom Taegyung "Iggy <iggy.eom@sendbird.com>
Co-authored-by: Mehdi ABAAKOUK <sileht@sileht.net>
Co-authored-by: Dongkeun Lee <3315213+zakaf@users.noreply.github.com>
Co-authored-by: woutdenolf <wout.de_nolf@esrf.eu>
Co-authored-by: Kurt McKee <contactme@kurtmckee.org>
Co-authored-by: Juraj Páll <palljuraj1@gmail.com>
Co-authored-by: Joan Fontanals <jfontanalsmartinez@gmail.com>
Co-authored-by: Stanislav Zmiev <zmievsa@gmail.com>
fix (#2566)
Fix unlink in cluster pipeline (#2562)
Fix issue 2540: Synchronise concurrent command calls to single-client mode. (#2568)
Fix: tuple function cannot be passed more than one argument (#2573)
Fix issue 2567: NoneType check before raising exception (#2569)
Fix issue 2349: Let async HiredisParser finish parsing after a Connection.disconnect() (#2557)
Fix issue with `pack_commands` returning an empty byte sequence (#2416)
Fix #2581 UnixDomainSocketConnection' object has no attribute '_command_packer' (#2583)
Fix #2581 UnixDomainSocketConnection' object has no attribute '_command_packer' .
Fix for `lpop` and `rpop` return typing (#2590)
Fixed CredentialsProvider examples (#2587)
Fixed issue #2598 - make Document class subscriptable
fix: replace async_timeout by asyncio.timeout (#2602)
Fix behaviour of async PythonParser to match RedisParser as for issue #2349 (#2582)
Fix (#2641)
fix: do not use asyncio's timeout lib before 3.11.2 (#2659)
Fix issue 2660: PytestUnraisableExceptionWarning from asycio client (#2669)
Fixing cancelled async futures (#2666)
Fix async (#2673)
Fix memory leak caused by hiredis (#2693) (#2694)
Fix incorrect usage of once flag in async Sentinel (#2718)
Fix topk list example. (#2724)
Fix `ClusterCommandProtocol` not itself being marked as a protocol (#2729)
Fix potential race condition during disconnection (#2719)
fix CI (#2748)
fix parse_slowlog_get (#2732)
fixes for issue #1128
fix create single_connection_client from url (#2752)
Fix `xadd` allow non negative maxlen (#2739)
Fix JSON.MERGE Summary (#2786)
Fixed key error in parse_xinfo_stream (#2788)
Fix dead weakref in sentinel connection causing ReferenceError (#2767) (#2771)
Fix dead weakref in sentinel conn (#2767)
fix redirects and some small cleanups (#2801)
Fix type hint for retry_on_error in async cluster (#2804)
Fix CI (#2809)
Fix async client with resp3 (#2657)
Fix `COMMAND` response in resp3 (redis 7+) (#2740)
Fix protocol version checking (#2737)
Fix parse resp3 dict response: don't use dict comprehension (#2757)
Fixing asyncio import (#2759)
fix (#2799)
fix async tests (#2806)
Fix socket garbage collection (#2859)
Fixing doc builds (#2869)
Fix a duplicate word in `CONTRIBUTING.md` (#2848)
Fix timeout retrying on Redis pipeline execution (#2812)
Fix type hints in SearchCommands (#2817)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants