Skip to content

Version 0.7.10

Latest

Choose a tag to compare

@vladimirvivien vladimirvivien released this 28 Nov 14:13
ce313bc

ktop Release v0.7.10

ktop v0.7.10 resolves UI freezes in long-running TUI sessions caused by lock inversion between health.APIHealthTracker state transitions and tview.Application.QueueUpdateDraw, synchronous reconnect execution on the UI event thread, and unsynchronized toast identifier handling in application.


Detailed Changes by Category

1. API Health Tracking & Deadlock Prevention (health, application)

Lock-Free Callback Dispatch & Structured Logging (health/api_health.go)

  • Problem / Context: APIHealthTracker previously held h.mu.Lock() while logging via slog and invoking onStateChange, onHealthy, onDisconnected, and onTryReconnect. Because onStateChange dispatches closures onto the tview UI loop via QueueUpdateDraw, and the UI draw loop reads IsAPIDisconnected() / IsAPIHealthy() (acquiring h.mu.RLock()), transient Kubernetes API errors could trigger an AB-BA deadlock freezing the TUI.
  • Implementation Details: Updated ReportSuccess, ReportError, scheduleRetry, and TryReconnect to snapshot pending callback references and transition state under h.mu, release h.mu.Unlock(), and then invoke slog and callbacks outside the lock.
  • Impact & Behavioral Notes: Background Kubernetes API disconnect retries, recovery transitions, and retry-timer callbacks no longer block or invert locks with the TUI render loop.

Asynchronous Reconnect Input Handling (application/app_ctrl.go)

  • Problem / Context: Pressing R or r while APIDisconnected previously called app.apiHealthTracker.TryReconnect() synchronously inside handleInputEvent on the tview UI goroutine, where onStateChange calls tapp.QueueUpdateDraw and self-deadlocks waiting for the UI thread. In addition, the early if app.HasActiveToast() guard returned key events before reaching the reconnect handler when the persistent disconnect toast ("API disconnected. Press R to reconnect") was visible.
  • Implementation Details: Dispatched go app.apiHealthTracker.TryReconnect() off the UI event thread inside if app.HasActiveToast() whenever app.IsAPIDisconnected() is true, and updated the standard 'R' / 'r' reconnect handler to dispatch go app.apiHealthTracker.TryReconnect() while guarding with !app.isFilterEditing().
  • Impact & Behavioral Notes: Pressing R or r from the disconnect banner triggers immediate asynchronous reconnection without blocking UI input processing or interfering with active / filter input.

2. Toast Notification Locking (application)

Scoped toastMutex Synchronization (application/app_ui.go)

  • Problem / Context: Toast creation and dismissal paths mutated p.currentToastID across dismissToastInternal without acquiring p.toastMutex, and showToastWithButtons / dismissToast held p.toastMutex across p.root.RemovePage, p.root.AddPage, p.root.SwitchToPage, p.tviewApp.SetFocus, and focusRestorationCallback.
  • Implementation Details: Removed dismissToastInternal, guarded every read and update of p.currentToastID directly under p.toastMutex in showToastWithButtons, dismissToast, and hasActiveToast, and released p.toastMutex before invoking any tview page or focus operations.
  • Impact & Behavioral Notes: Concurrent toast timeouts, button callbacks, and UI draw updates operate without lock-order cycles or data races under -race.

3. Concurrency Regression Tests (health, application)

  • Health Tracker Concurrency Test (health/api_health_test.go): Added TestAPIHealthTracker_NoDeadlockAcrossCallbacksAndReaders simulating a single-threaded QueueUpdateDraw loop alongside concurrent state readers, error transitions, reconnects, and recovery cycles.
  • Reconnect Key Deadlock Test (application/health_deadlock_test.go): Added TestApplication_ReconnectKeyDoesNotSelfDeadlock verifying that pressing 'R' while the disconnect toast is displayed triggers TryReconnect asynchronously without blocking the simulation UI loop.

Upgrade & Compatibility Notes

  • Backward Compatibility: Fully compatible with existing CLI flags, kubectl ktop plugin invocation, ~/.ktop/config.yaml, and --noui JSON/JSONL consumers.
  • Deprecations & Migration Actions: None.

Repository Metrics

 5 files changed, 309 insertions(+), 63 deletions(-)