Skip to content

Thread safety: _allSessionPoints accessed from multiple threads without synchronization #471

@tylerkron

Description

@tylerkron

Problem

DatabaseLogger._allSessionPoints (and its contained List<DataPoint> values) is written on a background thread during DisplayLoggingSession / LoadSampledData (Phase 2) while simultaneously being read on the UI thread by UpdateMainPlotViewport, UpdateSeriesFromMemory, ResetZoom, and FetchViewportDataFromDb.

This can cause InvalidOperationException (collection modified during enumeration), ArgumentOutOfRangeException (index into a list that was cleared), or corrupted data during pan/zoom while a session is loading.

Identified in

PR #467 double-check audit and Qodo review comment #2.4.

Suggested approaches (pick one)

  1. Single-thread ownership: Build all point data in local structures on the background thread, then Dispatcher.Invoke once to swap _allSessionPoints references on the UI thread.
  2. Locking: Add a lock(_sessionPointsLock) around all reads/writes/iterations of _allSessionPoints and contained lists.
  3. Pause viewport timers: Stop _viewportThrottleTimer during Phase 2 loading and restart after data is stable.

Option 1 is cleanest — it eliminates the shared mutable state entirely.

Files involved

  • Daqifi.Desktop/Loggers/DatabaseLogger.csDisplayLoggingSession, LoadSampledData, UpdateMainPlotViewport, UpdateSeriesFromMemory, ResetZoom, PrepareMinimapData

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions