Even I hope there is a cleaner way of doing this. Unfortunately, handling race conditions often does not have a clean way. In this case, the reason all this needs to be done is because of how Flume hides transactions as thread-local.