Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
alcarraz opened this issue Oct 20, 2023 · 2 comments

Comments

@alcarraz
Copy link
Contributor

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?

public void deployElement (Element e, String fileName, boolean encrypt, boolean isTransient)
throws ISOException, IOException, GeneralSecurityException
{
e = e.clone ();
XMLOutputter out = new XMLOutputter (Format.getPrettyFormat());
Document doc = new Document ();
doc.setRootElement(e);
File qbean = new File (deployDir, fileName);
if (isTransient) {
e.setAttribute("instance", getInstanceId().toString());
qbean.deleteOnExit();
}
if (encrypt) {
doc = encrypt (doc);
}
try (Writer writer = new BufferedWriter(new FileWriter(qbean))) {
out.output(doc, writer);
}
}

@alcarraz
Copy link
Contributor Author

alcarraz commented Oct 20, 2023

If agreed, I can implement the PR.

@ar
Copy link
Member

ar commented Oct 25, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants