Skip to content

fix(3scale_batcher): read batched report keys while holding the lock - #1614

Open
borisurbanik wants to merge 1 commit into
3scale:3scale-2.16-stablefrom
borisurbanik:backport/THREESCALE-16640-2.16-stable
Open

borisurbanik wants to merge 1 commit into
3scale:3scale-2.16-stablefrom
borisurbanik:backport/THREESCALE-16640-2.16-stable

Conversation

@borisurbanik

@borisurbanik borisurbanik commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

What

Backport of 79f35ae (PR #1611) to 3scale-2.16-stable

timer_task.lua is intentionally not changed in this backport: the nil guard
makes the throw unreachable, so the pcall defence is not needed on the
stable branch where the bar for generic-module behaviour changes is higher.

JIRA: https://redhat.atlassian.net/browse/THREESCALE-16640

Backport of 79f35ae (PR 3scale#1611) to 3scale-2.16-stable, without the
timer_task.lua pcall change.

ReportsBatcher:get_all() listed the shared dict keys before acquiring the
lock and then read them while holding it. There is one reporting timer per
worker and they all flush the same service, so a second worker could list a
key, lose the race for the lock, and find the key already deleted by the
time it ran. storage:get() then returned nil and the comparison below raised
"attempt to compare number with nil".

The raised error left the lock to expire on its own, which made every
request for that service wait the full 10s lock timeout in the access phase
before dropping its report. It also aborted the timer thread before
TimerTask could schedule the next run, so reporting stopped on that worker
until the configuration was reloaded.

Read the keys under the lock so deletes cannot interleave, and skip entries
that are gone anyway (eviction can still remove a key even under the lock).

timer_task.lua is intentionally not changed in this backport: the nil guard
makes the throw unreachable, so the pcall defence is not needed on the
stable branch where the bar for generic-module behaviour changes is higher.

Fixes: THREESCALE-16640
Cherry-picked-from: 79f35ae
@borisurbanik
borisurbanik requested a review from a team as a code owner November 6, 2026 11:07
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