jpos / jPOS

jPOS Project
http://jpos.org
GNU Affero General Public License v3.0
609 stars 461 forks source link

Q2.deployElement doesn't write the destination file atomically, which can make the deploy polling to fail #564

Open alcarraz opened 11 months ago

alcarraz commented 11 months ago

In Q2.deployElement we create the file directly in the deploy directory. I believe this may be causing what's reported in this stack overflow question.

Maybe we should do the same that is advised, of writing the file in a temporary file, maybe with a .tmp extension, and then move it to the final deploy name?

https://github.com/jpos/jPOS/blob/f0471696043559b51e3b075d22a6944b932df9f8/jpos/src/main/java/org/jpos/q2/Q2.java#L813-L832

alcarraz commented 11 months ago

If agreed, I can implement the PR.

ar commented 11 months ago

We can approach this in two ways:

Initiate the file with a .tmp extension and subsequently rename it. However, potential challenges could arise with Windows' move or when deploying to a FUSE file system.

Implement an internal Semaphore, given this is a Q2 method. While this seems more streamlined initially, it could pose issues if multiple Q2s utilize the same deploy. This scenario, albeit unusual, is still possible.

Both methods come with their respective advantages and limitations.