Publish on-demand log JSON atomically - #13
Draft
okt-limonikas wants to merge 2 commits into
Draft
Conversation
On-demand JSON files were written directly to their public paths. Apache could serve a file as soon as it was opened, so concurrent clients sometimes received empty or truncated JSON. Write node files and tree.json to same-directory temporary files and rename them only after a successful close. Preserve output permissions and reap temporary files abandoned by interrupted conversions without disturbing active writers. Link: ts-factory/bublik-ui#573 Link: ts-factory/bublik-ui#621 Signed-off-by: Danil Kostromin <danil.kostromin@icloud.com>
okt-limonikas
force-pushed
the
fix/atomic-log-json-generation
branch
from
August 4, 2026 15:45
834bec5 to
af190e1
Compare
okt-limonikas
marked this pull request as ready for review
August 4, 2026 15:47
okt-limonikas
marked this pull request as draft
August 4, 2026 16:14
Concurrent requests for a missing JSON file could start multiple converters for the same destination. This wasted resources and made the partial-file race more likely. Canonicalize requested paths and serialize generation through a bounded 256-slot lock pool. Recheck the target under the lock so waiters reuse the completed file, return explicit HTTP statuses, and keep generator diagnostics out of client responses. Link: ts-factory/bublik-ui#573 Link: ts-factory/bublik-ui#621 Signed-off-by: Danil Kostromin <danil.kostromin@icloud.com>
okt-limonikas
force-pushed
the
fix/atomic-log-json-generation
branch
from
August 4, 2026 16:20
af190e1 to
569be08
Compare
arybchik
reviewed
Aug 23, 2026
| # Outputs: | ||
| # HTTP response | ||
| ############################# | ||
| function internal_error_exit() { |
There was a problem hiding this comment.
I dislike that really different changes are mixed in one changeset. It makes the review harder.
Please, factor out introduction of these functions into separate patch.
| request_file=$(realpath -m -- "${request_file}") || internal_error_exit | ||
| case "${request_file}" in | ||
| "${canonical_root}"/* ) ;; | ||
| * ) not_found_exit ;; |
There was a problem hiding this comment.
Logically it is a separate enhancement not directly related to locking and serialization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix intermittent empty, truncated, or invalid JSON responses when multiple
clients request an uncached log node at the same time.
The converter now publishes complete JSON files atomically, while the CGI
handler ensures that only one request generates a given target.
Related to:
Problem
rgt-xml2jsonpreviously wrote directly to the public JSON path. Apache couldserve that file before serialization finished. Concurrent requests could also
start multiple converters that truncated and wrote the same file.
This appeared in the UI as an empty or unavailable selected test. Reloading or
navigating away and back worked after generation had completed.
You can test via this small bash script by pointing at some URL from apache log server
Example output
Be aware that this is flaky and some behave correctly and some fail so test with multiple nodes (large, small, etc...)
Like for this url
https://ts-factory.io/logs/dpdk-ethdev-ts/2024/03/24/virtio_virtio:tuor-cbs-speed-stack-00:14:19/json/Changes
tools/rgt: publish generated JSON atomicallytree.jsonto hidden files in the destination directory.rename().0666 & ~umaskfor a new file.Apache now sees either no public file or one complete JSON document. Cleanup
does not remove a temporary file that is still being written.
tools/log_server: serialize on-demand generationflockfiles.diagnostics to clients.
The bounded pool prevents attacker-controlled request paths from creating an
unlimited number of persistent lock files. Hash collisions only serialize
unrelated generation requests.