• Two problems I see right off:

    1. You may not want isolation level serializable for the whole package. That may cause unnecessary blocking in other processes.

    2. if the data flow fails, the semaphore is not released.