Skip to content

Proper cleanup for deployed process signaler#259

Merged
Tyrrrz merged 2 commits intoTyrrrz:masterfrom
xpherism:master
Sep 19, 2024
Merged

Proper cleanup for deployed process signaler#259
Tyrrrz merged 2 commits intoTyrrrz:masterfrom
xpherism:master

Conversation

@xpherism
Copy link
Copy Markdown
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

Comment thread CliWrap/Utils/WindowsSignaler.cs Outdated
…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
Comment thread CliWrap/Utils/WindowsSignaler.cs Outdated
@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
@Tyrrrz
Copy link
Copy Markdown
Owner

Tyrrrz commented Sep 19, 2024

Thanks!

heqianwang pushed a commit to workleap/wl-leap-local-dev that referenced this pull request Mar 20, 2025
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [CliWrap](https://github.com/Tyrrrz/CliWrap) | nuget | patch | `3.6.6` -> `3.6.7` |

---

### Release Notes

<details>
<summary>Tyrrrz/CliWrap (CliWrap)</summary>

### [`v3.6.7`](https://github.com/Tyrrrz/CliWrap/releases/tag/3.6.7)

[Compare Source](Tyrrrz/CliWrap@3.6.6...3.6.7)

#### What's Changed

-   Bump the nuget group with 6 updates by [@&#8203;dependabot](https://github.com/dependabot) in Tyrrrz/CliWrap#245
-   Bump the nuget group with 2 updates by [@&#8203;dependabot](https://github.com/dependabot) in Tyrrrz/CliWrap#252
-   Bump the nuget group with 3 updates by [@&#8203;dependabot](https://github.com/dependabot) in Tyrrrz/CliWrap#255
-   Proper cleanup for deployed process signaler by [@&#8203;xpherism](https://github.com/xpherism) in Tyrrrz/CliWrap#259
-   Bump the nuget group with 4 updates by [@&#8203;dependabot](https://github.com/dependabot) in Tyrrrz/CliWrap#260
-   Use `Encoding.Default` instead of `Console.OutputEncoding` as the default encoding by [@&#8203;Tyrrrz](https://github.com/Tyrrrz) in Tyrrrz/CliWrap#262

#### New Contributors

-   [@&#8203;dependabot](https://github.com/dependabot) made their first contribution in Tyrrrz/CliWrap#245
-   [@&#8203;xpherism](https://github.com/xpherism) made their first contribution in Tyrrrz/CliWrap#259

**Full Changelog**: Tyrrrz/CliWrap@3.6.6...3.6.7

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR is behind base branch, or PR is renamed to start with "rebase!".

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
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