Skip to content

Conversation

@cameron1729
Copy link

Rationale

We often see orphaned locks left in Redis. The hostname, while useful, is not surfaced prominently in AWS tooling.
Having the ability to override this and use an AWS ARN or similar alongside each lock would make it far easier to determine if a lock has been orphaned and is safe to manually release and also sets the stage for an automated solution. Hostnames are also routinely recycled, which can hide orphaned locks.

Implementing swappable identity providers allows us to choose metadata that better serves us when debugging locks.

Current state

The only current option is to wrap local_redislock\lock\redis_lock_factory inside another plugin and override methods, or to use other brittle hacks to mutate the lock value. This kind of approach is not ideal as it's fragile across upgrades and tough to test.

Implementation

Since modern Moodle has a DI container, and exposes the di_configuration hook which allows plugins to override the identity_provider binding - using DI is the cleanest approach. A param has also been added to the constructor to inject the identity service, so that if Moodle ever adds lock factories to the DI container properly, we can use DI the intended way (instead of doing a "service locator-ish" DI::get in the constructor.

The lock factory now pulls its metadata from an identity provider service
which allows plugins to specify alternative implementations (e.g., AWS ARN)
by listening to the DI configuration hook. The default listener in this plugin
(which maintains the hostname and PID combo) specifies priority 999 allowing
(effectively) any other plugin listener to automatically win.
@cameron1729 cameron1729 changed the title Identiy providers Allow swappable identiy providers Nov 12, 2025
@cameron1729 cameron1729 changed the title Allow swappable identiy providers Allow swappable lock identiy providers Nov 12, 2025
@cameron1729 cameron1729 changed the title Allow swappable lock identiy providers Allow swappable lock identity providers Nov 12, 2025
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