Skip to content

Module unblock on keys: updateStatsOnUnblock is called twice#13405

Merged
sundb merged 5 commits intoredis:unstablefrom
guybe7:module_block_key_stats
Jul 11, 2024
Merged

Module unblock on keys: updateStatsOnUnblock is called twice#13405
sundb merged 5 commits intoredis:unstablefrom
guybe7:module_block_key_stats

Conversation

@guybe7
Copy link
Collaborator

@guybe7 guybe7 commented Jul 10, 2024

This commit reverts the deletion of the condition !bc->blocked_on_keys that was accidentally introduced by #12817.
In case a blocked-on-keys module client is unblocked both moduleUnblockClientOnKey and moduleHandleBlockedClients are called which resulted in updateStatsOnUnblock being called twice

Now, that moduleHandleBlockedClients doesn't call updateStatsOnUnblock in case of unblocked module key-blocked clients, in the unlikely event that the module decides to call RM_UnblockClient on a key-blocked client, we need to call updateStatsOnUnblock from within moduleBlockedClientTimedOut, but since moduleBlockedClientTimedOut is not tread-safe we can't call it directly from withing RM_UnblockClient.
Added a new flag blocked_on_keys_explicit_unblock for that specific case, which will cause moduleBlockedClientTimedOut to be called from moduleHandleBlockedClients (which is only called from the main thread)

This commit reverts the deletion of the condition '!bc->blocked_on_keys' which was accidently introduced by redis#12817
In case a module blocked-on-keys client is unblocked both 'moduleUnblockClientOnKey' and 'moduleHandleBlockedClients' are called which resulted in 'updateStatsOnUnblock' being called twice
@guybe7 guybe7 requested a review from sundb July 10, 2024 05:46
@sundb
Copy link
Collaborator

sundb commented Jul 10, 2024

@guybe7 thanks, but i forget why i deleted it, please let me recall it.

Co-authored-by: debing.sun <[email protected]>
@sundb
Copy link
Collaborator

sundb commented Jul 11, 2024

@guybe7 from the report of ASAN thread, i dont see new race condition issue.

@guybe7
Copy link
Collaborator Author

guybe7 commented Jul 11, 2024

@sundb can we merge it?

@sundb sundb merged commit 81440a3 into redis:unstable Jul 11, 2024
@sundb sundb added the release-notes indication that this issue needs to be mentioned in the release notes label Jul 16, 2024
sundb added a commit to YaacovHazan/redis that referenced this pull request Apr 22, 2025
…3405)

This commit reverts the deletion of the condition `!bc->blocked_on_keys`
that was accidentally introduced by
redis#12817.
In case a blocked-on-keys module client is unblocked both
`moduleUnblockClientOnKey` and `moduleHandleBlockedClients` are called
which resulted in `updateStatsOnUnblock` being called twice

Now, that `moduleHandleBlockedClients` doesn't call
`updateStatsOnUnblock` in case of unblocked module key-blocked clients,
in the unlikely event that the module decides to call `RM_UnblockClient`
on a key-blocked client, we need to call `updateStatsOnUnblock` from
within `moduleBlockedClientTimedOut`, but since
`moduleBlockedClientTimedOut` is not tread-safe we can't call it
directly from withing `RM_UnblockClient`.
Added a new flag `blocked_on_keys_explicit_unblock` for that specific
case, which will cause `moduleBlockedClientTimedOut` to be called from
`moduleHandleBlockedClients` (which is only called from the main thread)

---------

Co-authored-by: debing.sun <[email protected]>
@YaacovHazan YaacovHazan moved this from Todo to Done in Redis 7.2 Backport Apr 29, 2025
funny-dog pushed a commit to funny-dog/redis that referenced this pull request Sep 17, 2025
…3405)

This commit reverts the deletion of the condition `!bc->blocked_on_keys`
that was accidentally introduced by
redis#12817.
In case a blocked-on-keys module client is unblocked both
`moduleUnblockClientOnKey` and `moduleHandleBlockedClients` are called
which resulted in `updateStatsOnUnblock` being called twice

Now, that `moduleHandleBlockedClients` doesn't call
`updateStatsOnUnblock` in case of unblocked module key-blocked clients,
in the unlikely event that the module decides to call `RM_UnblockClient`
on a key-blocked client, we need to call `updateStatsOnUnblock` from
within `moduleBlockedClientTimedOut`, but since
`moduleBlockedClientTimedOut` is not tread-safe we can't call it
directly from withing `RM_UnblockClient`.
Added a new flag `blocked_on_keys_explicit_unblock` for that specific
case, which will cause `moduleBlockedClientTimedOut` to be called from
`moduleHandleBlockedClients` (which is only called from the main thread)

---------

Co-authored-by: debing.sun <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-notes indication that this issue needs to be mentioned in the release notes

Projects

Development

Successfully merging this pull request may close these issues.

2 participants