[BUG] Preserve profile output ownership through teardown #768

Open
opened 2026-11-12 04:38:02 +01:00 by erikinkinen · 1 comment
Owner

Summary

Profile teardown follows its mutable stream field. Replacing that field with another caller-owned output can close the replacement while leaving the originally opened file alive, even though the profile reports that it is closed.

Reproduction

In a controlled host test, create a preparation profile and retain its first stream. Replace profile.stream with a second exclusive output, then call profile.close(). The call completes, profile.closed is true and the replacement is closed, but fstat on the first stream still succeeds. Both outputs belong to the test caller.

Expected and actual behavior

The original output must remain owned until its own close completes. Replacing bookkeeping must not redirect writes or teardown, erase a partial acquisition, or make an incomplete close look healthy.

Use an existing output-directory capability and a capturer enrolled before acquisition. Retain the profile and its output independently in the Scope retirement journal. Preserve bounded descriptor intervals, the existing profile format and cadence, and the original clocks and byte charges. The provider command also needs to retain the prospective profile before its constructor can acquire a file.

Environment and identity

  • Integration: 1b7396d1c50fadbcd4d5d5a7b6c7f51c6f3d2924.
  • Host native-build profiling on x86-64 Linux with Python 3.14; no guest-execution claim.
  • The caller already owns both output streams; the test changes internal bookkeeping to exercise cleanup.

Evidence and prior checks

The controlled test observed profile_claims_closed=true, original_stream_closed=false, replacement_stream_closed=true and original_fd_still_open=true. It explicitly drained both streams afterward.

The relevant code is PreparationProfile and Scope profile retirement.

Tracking

Supports #746 and the native-build work tracked by #65.

  • Retain constructor and output ownership before effects.
  • Retire the original profile through Scope and provider-command teardown.
  • Preserve profiling behavior and original accounting.
  • Cover replacement, omission, partial construction and uncertain close outcomes.
## Summary Profile teardown follows its mutable stream field. Replacing that field with another caller-owned output can close the replacement while leaving the originally opened file alive, even though the profile reports that it is closed. ## Reproduction In a controlled host test, create a preparation profile and retain its first stream. Replace `profile.stream` with a second exclusive output, then call `profile.close()`. The call completes, `profile.closed` is true and the replacement is closed, but `fstat` on the first stream still succeeds. Both outputs belong to the test caller. ## Expected and actual behavior The original output must remain owned until its own close completes. Replacing bookkeeping must not redirect writes or teardown, erase a partial acquisition, or make an incomplete close look healthy. Use an existing output-directory capability and a capturer enrolled before acquisition. Retain the profile and its output independently in the Scope retirement journal. Preserve bounded descriptor intervals, the existing profile format and cadence, and the original clocks and byte charges. The provider command also needs to retain the prospective profile before its constructor can acquire a file. ## Environment and identity - Integration: `1b7396d1c50fadbcd4d5d5a7b6c7f51c6f3d2924`. - Host native-build profiling on x86-64 Linux with Python 3.14; no guest-execution claim. - The caller already owns both output streams; the test changes internal bookkeeping to exercise cleanup. ## Evidence and prior checks The controlled test observed `profile_claims_closed=true`, `original_stream_closed=false`, `replacement_stream_closed=true` and `original_fd_still_open=true`. It explicitly drained both streams afterward. The relevant code is [PreparationProfile](https://git.erikinkinen.fi/erix/integration/src/commit/1b7396d1c50fadbcd4d5d5a7b6c7f51c6f3d2924/scripts/native_boot_profile.py) and [Scope profile retirement](https://git.erikinkinen.fi/erix/integration/src/commit/1b7396d1c50fadbcd4d5d5a7b6c7f51c6f3d2924/scripts/dynlink_heap_scope.py). ## Tracking Supports #746 and the native-build work tracked by #65. - [x] Retain constructor and output ownership before effects. - [x] Retire the original profile through Scope and provider-command teardown. - [x] Preserve profiling behavior and original accounting. - [x] Cover replacement, omission, partial construction and uncertain close outcomes.
erikinkinen added this to the Alpha 1 milestone 2026-11-12 04:38:02 +01:00
Author
Owner

Implemented in #770. Profiling now opens through an explicit retained output directory, and Scope reserves the original profile before construction. Teardown follows that original capture after current fields are lost or replaced; substituted stream callbacks and late progress are refused before effects.

Implemented in #770. Profiling now opens through an explicit retained output directory, and Scope reserves the original profile before construction. Teardown follows that original capture after current fields are lost or replaced; substituted stream callbacks and late progress are refused before effects.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
erix/integration#768
No description provided.