Skip to content

Snapshot() reads sessions, alerts, and daily total under separate locks #1

Description

@rajfirke

Problem

Collector.Snapshot() in internal/source/collector.go assembles DataMsg from three separate lock acquisitions:

  1. c.store.Snapshot() — acquires/releases ss.mu.RLock
  2. c.mu.Lock for alerts
  3. c.store.DailyTotal() — acquires/releases ss.mu.RLock again

Between these calls, the background goroutine can run processAllTails(), updating session metrics. The returned DataMsg can have session costs from time T but daily total from time T+delta.

Impact

Cosmetic — the TUI may briefly show numbers that don't add up. Self-corrects on the next 1-second tick. No crash or data loss.

Suggested Fix

Add a SnapshotWithTotal() ([]SessionMetrics, float64) method to SessionStore that returns both under a single RLock.

Files

  • internal/source/collector.go:192-245
  • internal/metrics/session.go

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingconcurrencyRace conditions, lock ordering, thread safetygood first issueGood for newcomers

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions