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

Proper cleanup for deployed process signaler #259

Merged
merged 2 commits into from
Sep 19, 2024
Merged

Conversation

xpherism
Copy link
Contributor

@xpherism xpherism commented Sep 14, 2024

On Windows calling GetTempFileName results in a 0 size unique file created to ensure the availability of the temp file name. These are not automatically deleted as per documentation (the OS probably will do some cleanup from time to time thou).

https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-gettempfilenamew

Using .NET 7 and below there is limit of 65535 unique temp files names as GetTempFileNameW is used (this limitation is removed in .NET 8+) If we look and the .NET 8 implementation (which I'm guessing follows the WIN32 implementation somewhat), a loop is use to find a unique temp filename, which at least as observed for .NET 6 on Windows, will result in very high CPU utilization when nearing the unique temp file name limit as the numbers of name collision becomes very high.

https://github.com/dotnet/runtime/blob/v8.0.8/src/libraries/System.Private.CoreLib/src/System/IO/Path.Windows.cs

To avoid problems with temp file leaking we simply generate our own temp filename using GetTempPath() and a UUID.

Closes #258

…empFileName

GetTempFileName create 0 size temp files to ensure availability of the generated temp filename, which are not removed when the WindowsSignaler is disposed. Instead we simply create our unique temp filenames using UUID, and thus we only create the actual temp (.exe) file that we actually need.
@xpherism xpherism changed the title WindowsSignaler now removes the 0 size tmp*.tmp file created when calling Path.GetTempFileName during dispose. WindowsSignaler now generates its own temp filename instead of using GetTempFileName Sep 19, 2024
@Tyrrrz Tyrrrz changed the title WindowsSignaler now generates its own temp filename instead of using GetTempFileName Proper cleanup for deployed process signaler Sep 19, 2024
@Tyrrrz Tyrrrz merged commit b7765e9 into Tyrrrz:master Sep 19, 2024
7 checks passed
@Tyrrrz
Copy link
Owner

Tyrrrz commented Sep 19, 2024

Thanks!

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

Successfully merging this pull request may close these issues.

WindowsSignaler is leaking tmp files
2 participants