Skip to content

fix(memcached): let clear_path raise connection errors - #196

Merged
allen0099 merged 1 commit into
masterfrom
fix/memcached-clear-path-errors
Sep 26, 2026
Merged

allen0099 merged 1 commit into
masterfrom
fix/memcached-clear-path-errors

Conversation

@allen0099

@allen0099 allen0099 commented Sep 26, 2026 •

Copy link
Copy Markdown
Owner

Closes #177.

Problem

MemcachedBackend.clear_path() wrapped its delete in except Exception: return 0. A connection failure was therefore reported as "nothing to clear", while delete() and every other method let the error through.

Change

Drop the try/except. clear_path() now reports errors the same way delete() does.

Note on pymemcache's own error handling

HashClient (ignore_exc=False, default retry_attempts=2, retry_timeout=1, dead_timeout=60) behaves like this:

  • It raises the OSError on the first failed call.
  • For the next second, every call on that server returns the command's default (None/False) without raising.
  • After the retries, it raises MemcacheError("All servers seem to be down right now").

This PR only removes the extra layer in clear_path(), which also hid the first error and the "all servers down" one. The silent defaults during the retry window affect every method, and are tracked in #197.

Tests

  • New test_memcached_clear_path_raises_when_the_server_is_unreachable points the backend at a closed port and expects ConnectionRefusedError. It needs no live server.
  • test_memcached_clear_path_exception asserted that the error was swallowed. It is now ..._propagates_client_errors, and expects the error.
  • Mutation check: with the except restored, exactly these two tests fail.
  • Full suite against live Redis and Memcached (CACHEX_REQUIRE_LIVE_SERVERS=1): 849 passed, 100% coverage.

clear_path() caught every exception and returned 0, so a connection
failure looked like "nothing to clear", while delete() and the other
methods let the error through.

Closes #177
@allen0099 allen0099 added this to the 0.3.8 milestone Sep 26, 2026
@allen0099 allen0099 added bug Something isn't working backends Cache backends and their atomic primitives labels Sep 26, 2026
@allen0099
allen0099 merged commit 59348f2 into master Sep 26, 2026
11 checks passed
@allen0099
allen0099 deleted the fix/memcached-clear-path-errors branch September 26, 2026 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backends Cache backends and their atomic primitives bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Memcached clear_path hides connection failures

1 participant