Skip to content

Commit e0adc3c

Browse files
author
peco-engineer-bot[bot]
committed
learn: retrospective learnings
Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>
1 parent 96572a2 commit e0adc3c

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Learning journal 2026-11-19
2+
3+
### 2026-11-19: Async lifecycle and FFI — Reserve the async flush lock synchronously before spawning, so a burst spawns one task
4+
**Context:** In PR #478, TelemetryClient::enqueue spawned a flush_once_if_idle task every time the queue reached batch_size, so a burst of 2,000 enqueues spawned many tasks that then fought over flush_lock. The fix made flush_lock an Arc<tokio::sync::Mutex>, takes it with try_lock_owned() before spawning, moves the OwnedMutexGuard into the task, and skips the spawn when the lock is held. The tests count spawned tasks with runtime.metrics().num_alive_tasks() on a current_thread runtime that has not run yet. They also use a paused exporter to check that events enqueued during an export are still flushed by the timer and by close.
5+
**Rule:** When synchronous code triggers lock-guarded async work, take an owned guard (try_lock_owned) before spawning and move it into the task so bursts spawn at most one task; make sure a later flush path (timer/close) picks up triggers skipped while the lock was held, and test the spawn count with num_alive_tasks on a current_thread runtime that has not been started.
6+

‎.claude/knowledge/lessons.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Lessons
22

3-
<!-- distilled-through: 2026-11-18 -->
3+
<!-- distilled-through: 2026-11-19 -->
44

55
## Public API and bindings
66
- L-0001 (4×, #250 #184 #372): Preserve public Rust compatibility: non-exhaustive structs need external builders, public enums need fallback arms, and breaking 1.x type changes require a major release.
@@ -72,6 +72,7 @@
7272
- L-0061 (1×, #466): Coalesce requests without holding locks across network calls: key attempts, share same-key errors/results, recheck after different-key waits, and detach work from individual waiter cancellation.
7373
- L-0062 (1×, #431): A non-consuming peek buffers errors as well as data for the next read. Test one-shot-error-then-EOF; optional enrichment must not silently turn server success into execution failure.
7474
- L-0063 (1×, #451): Cached terminal ExecuteResponse payloads must be complete and take-once. Clear on error, close, Drop, owner release, timeout and fresh status polls; document how terminal observations retain inline results.
75+
- L-0096 (1×, #478): When sync code triggers lock-guarded async work, take try_lock_owned before spawning and move the guard in, so bursts spawn one task; ensure timer/close flushes cover skipped triggers. Count spawns via num_alive_tasks on an unstarted current_thread runtime.
7576

7677
## Arrow results and metadata
7778
- L-0064 (2×, #301 #373): Empty catalog/pattern semantics vary by metadata operation; test short-circuit ordering and avoid turning an empty request into catalog=None (all catalogs). GetFunctions accepts meaningful empty catalogs.

0 commit comments

Comments
 (0)