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

Filename collisions in sort files #112

Open
jodavies opened this issue Jul 26, 2016 · 11 comments
Open

Filename collisions in sort files #112

jodavies opened this issue Jul 26, 2016 · 11 comments
Labels
enhancement New feature or request

Comments

@jodavies
Copy link
Collaborator

jodavies commented Jul 26, 2016

Now that the sort files can be put in a different directory to the scratch files, (TempDir != TempSortDir), it is not safe to assume that sort files can be created with the same base filename.

For eg, if I start tform on a script which creates sort files with

#: TempDir /foo1

and another with

#: TempDir /foo2
#: TempSortDir /foo1

the second instance of tform will overwrite the existing xformxxx.sFN of the first, causing it to crash when it comes to merge the patches.

I suppose one way to avoid this is to always use -M, but this is not the default behaviour. Otherwise, threads must check each and every time they create a sort file.

Thanks,
Josh.

EDIT: since Takahiro mentions tempsortdir in the changelog for 4.2, this could be worth looking at? It suffices to enforce -M if TempDir!=TempSortDir, at least if the locations are not on a shared network filesystem...

@vsht
Copy link

vsht commented Apr 1, 2021

I'm kind of wondering how unique the sort files become when the -M option is used? Is there still a chance that when
running multiple tform processes and setting FORMTMP to /tmp a crash due to overwriting may occur?

I came up with my own workaround by using sth like

tfmTformTmpDir="$(mktemp -d)";
cleanup="yes"
tform -t "$tfmTformTmpDir" ...;
rm -rf $tfmTformTmpDir

which creates unique subfolders for each tform process. However, if there is a reliable built-in mechanism available,
I'd rather use that than reinventing the wheel.

@jodavies
Copy link
Collaborator Author

jodavies commented Apr 1, 2021

-M means the filename will use the first last 5 digits of the pid. It is unlikely that there will be a collision, but I think it is not guaranteed.

@vsht
Copy link

vsht commented Apr 1, 2021

I see, thanks. Then I'll try using that and see if it suits me. On the cluster this is never an issue, since each tform
process gets a unique environment, but on my laptop (Ryzen 4750U with 8C/16T) I have to take some precautions by hand.

@vermaseren
Copy link
Owner

vermaseren commented Apr 1, 2021 via email

@jodavies
Copy link
Collaborator Author

jodavies commented Apr 1, 2021

Indeed, on clusters usually there are no issues. On your laptop you would have to have two tform processes running whose pid differs by precisely 100000.

This is due to startup.c's int num = ((int)GetPID())%100000;

@vermaseren
Copy link
Owner

vermaseren commented Apr 1, 2021 via email

@jodavies
Copy link
Collaborator Author

jodavies commented Apr 1, 2021

This PR is vaguely related and proposes the same scheme for the names #284 .

@tueda tueda added the enhancement New feature or request label Apr 2, 2021
@vsht
Copy link

vsht commented Apr 2, 2021

But that would mean that you loose
those old files. Normally that is no disaster, but in principle old .str files can be used in a
Load statement to recover their contents.

In fact, large leftover sort files that remain in the case of FORM crashing or aborting the evaluation
is something I was always wondering about. Of course, from the developer point of view those
can be quite valuable for debugging, but I guess that an ordinary user is never interested in them
except from the fact that they need to be removed by hand.

Perhaps as a suggestion for some future version, it would be cool to have a command line argument
telling FORM to remove all temporary files before terminating.

@vermaseren
Copy link
Owner

vermaseren commented Apr 2, 2021 via email

@vsht
Copy link

vsht commented Apr 2, 2021

I see, thanks.

Of course, if one runs FORM from a shell script and that script creates a unique TEMP directory
for FORM, the script will as well remove it after the FORM process ends (gracefully or not).

@tueda
Copy link
Collaborator

tueda commented Apr 2, 2021

Technically, maybe mkstemp + unlink would work for automatically removing all temporaries (#14 (comment)), but using this idea in the FORM source code can be highly nontrivial...

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

No branches or pull requests

4 participants