Skip to content

Fix Fail2Ban and Allow2Ban not banning with dalli 4 and 5 - #721

Draft
santib wants to merge 2 commits into
rack:mainfrom
santib:ci-dalli
Draft

Fix Fail2Ban and Allow2Ban not banning with dalli 4 and 5#721
santib wants to merge 2 commits into
rack:mainfrom
santib:ci-dalli

Conversation

@santib

@santib santib commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

Problem

With dalli 4 and 5, Fail2Ban and Allow2Ban never ban when the store is a Dalli::Client (directly or through a ConnectionPool).

Fail2Ban#ban! writes the Integer 1, and DalliProxy#write passes it to client.set(..., raw: true). Dalli 3 converted it with to_s; dalli 4 and 5 raise instead:

Dalli raw mode requires string values, got: Integer (Dalli::MarshalError)

DalliProxy rescues Dalli::DalliError and returns nil, so the ban key is never written and banned? is always false. Throttling is not affected because it uses memcached's incr, which does not go through the serializer.

Fix

Call value.to_s before the raw set in DalliProxy#write. Same behavior as dalli 3 did internally.

Verification

Adds dalli 4 and dalli 5 to the CI matrix (appraisals and gemfiles, excluding the Ruby versions each one does not support: dalli 4 requires Ruby >= 3.1, dalli 5 requires Ruby >= 3.3). Without the fix, works for fail2ban and works for allow2ban in spec/acceptance/stores/dalli_client_spec.rb fail on every dalli 4/5 job (expected 403, got 200).

Santiago Bartesaghi added 2 commits September 8, 2026 14:26
Dalli 4 and 5 are the current major versions and the suite only ran
against dalli 3. Add appraisals and gemfiles for both, and exclude the
Ruby versions each one does not support (dalli 4 requires Ruby >= 3.1,
dalli 5 requires Ruby >= 3.3).
Dalli 4 and 5 raise Dalli::MarshalError when a raw set receives a
non-String value, while Dalli 3 converted it with to_s. DalliProxy
rescues DalliError and returns nil, so Fail2Ban and Allow2Ban never
wrote their ban key and never banned.
@santib santib changed the title ci: test against dalli 4 and dalli 5 Fix Fail2Ban and Allow2Ban not banning with dalli 4 and 5 Sep 8, 2026
@santib
santib requested a review from grzuy September 8, 2026 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant