Skip to content

fix: claim queued telemetry files before sending them - #34

Merged
rajamatt merged 8 commits into
mainfrom
dev/mara/telemetry-outbox-claims
Oct 30, 2026
Merged

rajamatt merged 8 commits into
mainfrom
dev/mara/telemetry-outbox-claims

Conversation

@rajamatt

@rajamatt rajamatt commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

GitHub Issue (If applicable): unoplatform/uno-private#2462

PR Type

What kind of change does this PR introduce?

  • Bugfix

What is the current behavior?

Every desktop Telemetry instance on a machine, in any process, queues events in the same folder (<temp>/.uno/telemetry) and runs its own sender. Nothing stops two senders from taking the same file: Peek only skips files that the same instance already picked up. A file stays on disk until its sender has posted and deleted it, so every other sender that polls in that window posts it too. Idle instances poll as well, so a component that never tracks anything still re-sends everyone else's events.

When a delete fails, Delete logs it and moves on. The same sender then picks the file up again on its next poll (1 ms later) and keeps posting it until the file is 2 hours old. On Linux, /tmp is shared between users. A user who can read another user's queue but not delete from it ends up in this loop.

What is the new behavior?

  • A sender claims a file before sending it. It holds the queued file open exclusively while it reads, sends and deletes it: FileShare.Delete on Windows (no other open can share it), FileShare.None elsewhere (.NET takes an exclusive lock). No other sender, in this process or another, can open the file during that time.
  • Unsent files go back to the queue. Closing the file without deleting it (a retryable failure, a shutdown, or the process dying) returns it to the queue. Nothing is left behind to clean up.
  • A sent file is never sent again. If the delete fails after the send, the sender empties the file before letting go of it. Whoever finds it next moves it to .corrupt instead of sending it, even after the sender's process has exited.
  • A file the process can't open for writing is skipped, for example one that belongs to another user.
  • The queue moves to <temp>/.uno/telemetry/outbox. Older versions of the library don't claim files, and they would keep re-sending anything left in .uno/telemetry. They only look at the top level of that folder, so they never see the subfolder.

Also:

  • Loading: the transmission is read through its claim, since a claimed file can't be opened again, even by the same process.
  • File sizes are now read from the file system rather than by opening files, for the same reason.

Why not claim by renaming the file: on Windows, File.Move opens the source and renames it through that open handle. When several threads race to rename the same file, every one that opened it before the first rename succeeds. A test with 4 threads succeeded on all 4 in every one of 20,000 rounds. The exclusive open had exactly one winner in 5,000 rounds on Windows (.NET 10) and Linux (.NET 8 and 10).

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tested code with current supported SDKs
  • Docs have been added/updated which fit documentation template. (for bug fixes / features)
  • Unit Tests and/or UI Tests for the changes have been added (for bug fixes / features) (if applicable)
  • Wasm UI Tests are not showing unexpected any differences. Validate PR Screenshots Compare Test Run results.
  • Contains NO breaking changes
  • Updated the Release Notes
  • Associated with an issue (GitHub or internal)

Other information

Tests: new PersistenceChannelSharedFolderTests covering:

  • two storages sharing a folder (only one gets the file)
  • a file that isn't deleted going back to the queue
  • a file that can't be claimed being skipped
  • a delete that fails after a send (not sent again, even once its sender lets go of the file)
  • an end-to-end run where three channels share a folder and post to a local HTTP listener

Before the fix, run against main, 4 of these 5 tests fail. The end-to-end test counts 58 to 60 POSTs for 20 events.

After the fix, all 122 unit tests pass on Windows (.NET 8) and on Linux (WSL Ubuntu 24.04, .NET 8.0.33 and .NET 10.0.10, run as a non-root user so the permission tests apply). The shared-folder tests passed 5 runs in a row on Windows.

Not tested: .NET Framework (the VSIX build uses the same Windows sharing rules) and macOS.

Limits:

  • Advisory lock outside Windows: every .NET FileStream respects it, but it is off when DOTNET_SYSTEM_IO_DISABLEFILELOCKING is set, when the netstandard2.0 build runs on Mono, or when the temp folder is on NFS.
  • Rare resends: if a process dies after posting but before deleting, that event is sent once more by another sender. The same goes for a sent file that can be neither deleted nor emptied.
  • Older consumers: components still on older versions of the library keep their current behavior until they update. They share the old folder only with each other.
  • Old folder: files queued by older versions stay in .uno/telemetry. This version never reads or cleans that folder, so only older versions send or expire them.

🤖 Generated with Claude Code

@rajamatt rajamatt self-assigned this Oct 28, 2026
Comment thread src/Uno.DevTools.Telemetry/Telemetry.cs Dismissed
rajamatt and others added 2 commits October 28, 2026 15:46
Every Telemetry instance on a machine shares one queue folder and runs
its own sender, and nothing stopped two senders from sending the same
file, so events were posted once per sender that saw them. A file whose
deletion failed was also sent again on every poll.

A sender now holds a queued file open exclusively (FileShare.Delete on
Windows, an exclusive lock elsewhere) while it sends and deletes it.
Closing it without deleting returns it to the queue, including when the
process dies. A file that could not be deleted after being sent stays
held until its deletion succeeds. A file the process can't open for
writing is skipped instead of sent.

The queue moves to .uno/telemetry/outbox, which older versions of the
library, that don't claim files, never look into.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@rajamatt
rajamatt force-pushed the dev/mara/telemetry-outbox-claims branch from a18bf42 to fe821bd Compare October 28, 2026 19:46
- state why the generic catch clauses in TryClaim and
  DeleteUndeletedClaims are deliberate
- dispose the test channels with using declarations
- narrow the best-effort cleanup catch in the shared folder tests

Co-Authored-By: Claude Opus 5.5 <[email protected]>
rajamatt and others added 2 commits October 28, 2026 16:16
Holding a sent file open until its deletion succeeded only kept it from
being sent again while the process lived, and kept a handle open for
each such file. The file is now emptied through its claim and released:
whoever finds it next quarantines it as corrupt instead of sending it.

- the test restores permissions before the other storage peeks, so it
  checks the outcome rather than the denied write
- a file the process isn't allowed to open is skipped without logging

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
rajamatt and others added 2 commits October 28, 2026 16:24
Narrowing them only answered the generic-catch rule: cleanup is best
effort, and any accept failure means the test endpoint stopped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@rajamatt
rajamatt marked this pull request as ready for review October 28, 2026 20:44
@rajamatt
rajamatt requested a review from carldebilly October 28, 2026 20:44
@mergify

mergify Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

@rajamatt
rajamatt merged commit 5214e1b into main Oct 30, 2026
11 checks passed
@rajamatt
rajamatt deleted the dev/mara/telemetry-outbox-claims branch October 30, 2026 15:43
opensource-fork-sync Bot pushed a commit to cla7aye15I4nd/opensource-unoplatform__uno that referenced this pull request Oct 30, 2026
Picks up the queued-file claim fix (unoplatform/uno.devtools.telemetry#34):
each sender now holds a queued telemetry file open exclusively while it
sends it, so senders sharing the temp folder no longer post the same
events several times.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@agneszitte

Copy link
Copy Markdown
Member

/unobot prepare-release --commit-message-pattern "ci: Set version to '{0}'"

@unodevops

Copy link
Copy Markdown
Contributor

The release branch release/stable/1.4 has been created from aff716d and the PR #36 has been created for the version bump.

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

Successfully merging this pull request may close these issues.

5 participants