-
Notifications
You must be signed in to change notification settings - Fork 79
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
Fixed cleanup of temporary files from tasks #1142
Conversation
2d062e6
to
548d306
Compare
@@ -92,6 +96,10 @@ def validate(self): | |||
"service script, must end with the 'InRelease' file name!" | |||
) | |||
raise RuntimeError(message) | |||
files_to_cleanup.append(inline_path) # Track file for cleanup | |||
directories_to_cleanup.append( | |||
os.path.dirname(inline_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we really clean up the directory AND the file?
would it be better to create allt the temp files one specific temp directory and then ONLY remove this temp directory?
I don't know what the os.path.dirname(inline_path) directory is but if it would be /tmp or /var/tmp we are ruined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Each task will create their own tmp.{task-id-slug}
directory in /tmp/
. If I don't clean them up than you end up with a lot of empty directories.
Changing it that they all get created into a specific directory seems more involved.
The inline_path
gets taken from the input:
{
"signatures": {
"inline": "<relative_path>/InRelease",
"detached": "<relative_path>/Release.gpg",
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we have one directory for each task, how about saving the tmp directories path for each task and after the task finished (or an exception occurs), remove the directory completely?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should work like this now? It doesn't use the pulpcore task but creates its own temp directory. But I'm not sure I follow exactly what you mean. It's better to just delete it after the validation is done because we won't need it anymore.
To my knowledge, each task is performed in a temporary directory: Is that mechanism somehow not working? |
Not sure but the tmp dirs that are created for the signing service stuff look like this:
|
2123727
to
7ec775f
Compare
I do not see any new temporary directory being created here: So I assume at this point the process should "be" in the temporary directory of the task. |
I think so. The signing service script we use on production instances has:
It then passes the paths of the created files back to Pulp via the return value. I presume pulp_deb then turns those files into publication artifacts, and once that is done, it should cleanup the files (as well as the containing temp directory)? |
Yes the signing script does create tmpfiles this was an issue with the files created by the tests. The workaround here is that I added a log for the signing script that will be used during the cleanup in the signing service fixture |
I'd prefer if we can teach the signing script to write files in the current directory that then is already a temporary directory. |
Agree, or the signing service should be responsible to cleanup temp files itself. |
Would this imply teaching pulpcore to send in an extra parameter to the script? Does [https://github.com/pulp/pulpcore/blob/6a2d120a10b7a696a1282087eb51c5112cbb8351/pulpcore/app/models/content.py#L788](the pulpcore sign method) even have a way of knowing it is being called from a task? How can it receive the temp folder path?
The signing script returns what files it created as the return value. I guess manually cleaning those up, is what this PR is trying to do. I don't think the signing script could be made to clean up behind itself, since it has no way of knowing when Pulp is done with the files. |
As far as i see, this script should only be called in two circumstances:
In both cases, I expect the CWD (current working directory) to be a temporary one. If that is not true, that's the thing we should seek to fix. [0] https://github.com/pulp/pulpcore/blob/main/pulpcore/app/models/content.py#L903 |
@mdellweg I will have a go at testing a signing service script that just creates the file in the working directory. |
The cwd is always the root of the project never the tmp directory. So @quba42 suggestion to expand the the Still pondering if there might be another solution that doesn't involve a change in pulpcore. |
Honestly, at this point, i think it is a bug in pulpcore and should be fixed there. It must be possible to call the signing script inside of a specific directory. |
7ec775f
to
a068a7a
Compare
a068a7a
to
8671b97
Compare
This PR now requires this pulpcore PR pulp/pulpcore#5924 What changed is that now the The sync task still unzips the Package archive from upstream and saves it in the /tmp/ directory as well. This one needs manual cleanup since the file gets used out of content scope. With the changes all relevant tmp files should now properly be cleaned up. |
8671b97
to
a22a9ac
Compare
Thanks to @mdellweg I was able to achieve the same thing without relying on a pulpcore by using environment variables change see: pulp/pulpcore#5924 (comment) |
So i did some experimentation. And indeed, i am pretty certain, that the script inherits the cwd of the task, which is beneath the tasks workers working directory and so we already have two levels of cleanup for it. |
@mdellweg I'm not sure, really. If I call |
a22a9ac
to
330069a
Compare
- Add temp dir to env variables for signing service. - Ensure proper cleanup of uncompressed files in synchronization tasks. closes pulp#1141
330069a
to
03af39f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have one minor suggestion. It is a take it or leave it kind of thing, so I am not waiting with the ACK.
closes #1141