Fix LogConfig ID lifecycle - #608
Open
ataffanel wants to merge 7 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes the host-side LogConfig ID lifecycle so log block IDs can wrap and be reused safely without stale Log.log_blocks entries capturing replies/log data for reused IDs. It introduces an acknowledgement-owned “lease” model for log block IDs, aligning host and firmware state across delete/reset/disconnect and concurrent lifecycle commands.
Changes:
- Replace modulo ID counter behavior with a thread-safe free-ID pool covering the full
0..255range, releasing IDs only after delete acknowledgements. - Serialize log lifecycle commands (create/start/stop/delete/reset/disconnect) and validate registrations after packet sends to prevent stale follow-up actions.
- Add comprehensive unit tests for ID reuse, delete/reset/disconnect behavior, retries, and concurrency.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| cflib/crazyflie/log.py | Implements ID leasing, deferred release on delete ack, reset/disconnect draining, and command serialization with registration validation. |
| test/crazyflie/test_log.py | Adds tests covering ID wrap/reuse, idempotent delete, reset/disconnect semantics, retry behavior, and concurrent registrations. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+601
to
+617
| with self._registration_lock: | ||
| if self._reset_pending: | ||
| return | ||
| self._reset_pending = True | ||
| self._ids_ready = False | ||
| self._available_config_ids.clear() | ||
|
|
||
| pk = CRTPPacket() | ||
| pk.set_header(CRTPPort.LOGGING, CHAN_SETTINGS) | ||
| pk.data = (CMD_RESET_LOGGING,) | ||
| try: | ||
| self.cf.send_packet( | ||
| pk, expected_reply=(CMD_RESET_LOGGING,)) | ||
| except Exception: | ||
| with self._registration_lock: | ||
| self._reset_pending = False | ||
| raise |
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.
Abstract
Fix repeated
LogConfigcreation and deletion so applications can use logging for more than one byte-sized ID cycle without stale host-side blocks capturing reused IDs. Log block IDs are now managed as acknowledgement-owned leases, keeping host and firmware lifecycle state aligned across deletion, reset, disconnect, and concurrent commands.Closes #577.
Why
The previous implementation incremented an ID counter modulo 255 but never removed acknowledged-deleted configurations from
Log.log_blocks. Once an ID wrapped, reply and log-data lookup found the stale configuration first. This made the firmware appear to run out of log blocks after repeated create/read/delete operations even though it had deleted them correctly.The fix waits for the firmware deletion acknowledgement before releasing an ID. This is important because releasing earlier could route an in-flight reply or data packet to a newer configuration using the same opaque handle.
What changed
0..255ID range with a thread-safe FIFO free-ID pool.DELETEsucceeds or returnsENOENT; failed deletion retains the lease and can be retried.LogConfigspecification to be registered again with a fresh lease.LogConfigErrorfor invalid lifecycle transitions while keeping detached cleanup calls harmless.Verification
uv run python -m unittest discover ./test— 219 tests passed.