Infinite loop in while-hasNext
This is quite a common approach to interate over a collection
while (iterator.hasNext()) {
UnitOfWork work = iterator.next();
do(work);
}
But what if the iteration is not over a simple in-memory data structure, but we are interacting with a another subsystem or application over a similar interface.
In such setups it is highly recommended system A implements a protection logic for duplicate work. It happened to me recently that system B started to respond with the same UnitOfWork over and over, rendering system A into an infinite loop.
The protection may consist in comparing previous UnitOfWork with the new one and if they are the same either gracefully ignore it or report an error (eg: break the loop).
Another approach would be to persist some sort of identification of the UnitOfWork (eg: id, signature). If a new UnitOfWork has the same identifier as something that we have in the past work storage, again we can ignore and/or report the error.
Background:
It was quite a relaxing day which I spent attending the VoxxedDay conference. When I got home, I opened my laptop to check the emails, when a colleague approached me on Teams to ask for my help in for above production issues.
Comments
Post a Comment