Repository navigation
Description
On Derby, DefaultUserController.authorizeUser takes the PERSON read lock (StatementLock, a fair ReentrantReadWriteLock) and calls the authorization plugin while holding it. If the plugin calls updateUser in there (an LDAP plugin creating the account on first login, for example) and an admin deletes any user at the same moment, the two threads wait on each other for ever. After that every login and every authenticated API request hangs until the engine is restarted.
Only Derby takes this lock (vacuumPersonTable is only in derby-user.xml).
Lock order, engine v4.7.0 (main at dcd48b9, read but not run, has the same order at lines 292/300, 134 and 222/233):
- Login thread:
authorizeUsertakes the PERSON read lock (DefaultUserController.java:281), calls the plugin (:289), plugin callsupdateUser, which issynchronized(:124) and waits for the controller's monitor. - Delete thread:
removeUserissynchronized(holds the monitor) and then asks for the PERSON write lock (:222), which waits for the login thread's read lock. - Every later login asks for the read lock (:281) and queues behind the waiting writer, because the lock is fair.
Measured on 4.7.0 with Derby, RBAC 1.3.0 and an LDAP authorization plugin that creates the account on first login. The directory URL list started with an address that never answers, so the login stayed inside authorizeUser for the 8 s connect timeout:
- Start a first login for a directory user (plugin creates the account).
- Two seconds later, as admin, delete any other user.
- Two seconds later, log in as admin.
All three requests hung (curl gave up after 90, 60 and 40 s), and so did a fresh admin REST request. Thread dump:
"UserServlet Thread (Login)" BLOCKED (on object monitor)
at ...DefaultUserController.updateUser(DefaultUserController.java:124)
- waiting to lock <0x00000000f1b00098> (a ...DefaultUserController)
at <plugin>.create(...)
at ...DefaultUserController.authorizeUser(DefaultUserController.java:289)
"UserServlet Thread (Remove user)" WAITING (parking)
- parking to wait for <0x00000000f2558fc8> (a ReentrantReadWriteLock$FairSync)
at ...DefaultUserController.removeUser(DefaultUserController.java:222)
- locked <0x00000000f1b00098> (a ...DefaultUserController)
"UserServlet Thread (Login)" WAITING (parking)
- parking to wait for <0x00000000f2558fc8> (a ReentrantReadWriteLock$FairSync)
at ...DefaultUserController.authorizeUser(DefaultUserController.java:281)
Only a restart cleared it. Neither the new account nor the delete had been written.
A plugin can't work around this: the lock is taken before the plugin is called. Possible fixes:
- Release the read lock before calling the authorization plugin, and take it only around the engine's own password check.
- Or take the write lock in
removeUserbefore entering the monitor (same order as login).
Co-authored with Claude Code.
Activity