Race condition on mod-patron-blocks when handling parallel check-out requests
Summary
In the process of analyzing the problem with the loan policy limits (Concurrent Check-outs via Self-check do not check for patron item limits, more details on the link https://wiki.folio.org/pages/viewpage.action?spaceKey=~Raman+Auramau&title=CIRC-1345), another potential problem was revealed when processing several check-out requests in parallel - this time with the so-called automated patron block. This document describes the context and some details of the mentioned problem.
Context
The automated patron block is the calculation and verification of limits at the level of patron.
The mechanism is as follows -
- at the very beginning of processing a check-out request, a request is made to the mod-patron-blocks for the presence of a patron block.
- If there is no blocking, then the following steps are performed on the check-out flow,
- and at the very end, already when creating a loan, a notification is sent that the loan has been created.
- Notification goes through OkApi to the mod-pub-sub, then to Kafka. In turn, the mod-patron-blocks is subscribed to these notifications in the mod-pub-sub
- After a while the mod-patron-blocks receives this notification.
- Having received the notification, the mod-patron-blocks checks its rules and limits, and when the conditions are met, it blocks the patron.
As a result, there is a significant gap between, say, the creation of the last permitted loan (step 3 from the above), and the moment when it is checked and processed in mod-patron-blocks (step 6).
The image below shows the described flow as a sequence diagram.
Apparently, to date, this problem has not yet manifested itself (at least, it has not been reported as a bug).