Skip to content

Fix crash when searching in the Python Packages dialog - #1795

Open
deepratna-awale wants to merge 1 commit into
LykosAI:mainfrom
deepratna-awale:fix-python-packages-search-crash
Open

deepratna-awale wants to merge 1 commit into
LykosAI:mainfrom
deepratna-awale:fix-python-packages-search-crash

Conversation

@deepratna-awale

Copy link
Copy Markdown

Fixes #693

Problem

Searching in Packages → ⋯ → Python Packages can crash Stability Matrix (e.g. typing "ja" to find jax). Pasting the full name works around it.

Selecting a package loads its details (pip show / pip index versions) via LoadExtraInfo(...).SafeFireAndForget() with no exception handler. With no handler, AsyncAwaitBestPractices lets the exception escape, so anything other than a ProcessException (e.g. FileNotFoundException from the uv/pip/pyvenv.cfg checks in the venv runner, InvalidOperationException from PipIndexResult.Parse, ArgumentOutOfRangeException from PipShowResult.Parse) is rethrown on the UI thread and ends the app.

The list box uses SelectionMode="AlwaysSelected", so as the search filter narrows the list the selection jumps to a new package on almost every keystroke. Each jump started another details load, and those loads overlapped against the same venv, each one rewriting pyvenv.cfg and spawning its own pip processes. Pasting the name changes the selection once, which is why the workaround helps.

Changes

  • PythonPackagesViewModel
    • Failures while loading package details are logged as warnings instead of being rethrown on the UI thread.
    • Only one package's details load at a time (SemaphoreSlim). A load still waiting for its turn is dropped when the selection moves on, and a load whose package is no longer selected is skipped.
    • No load is started for an item that is already loading, or before the venv path is known.
    • Venv runner creation moved into one helper (it was copied in three places), with an internal factory hook for tests.
  • PythonPackagesItemViewModel.LoadExtraInfo takes a venv runner factory instead of a path plus PyBaseInstall, and skips if it is already loading.
  • PipIndexResult.Parse returns no versions instead of throwing when the output has no Available versions: line.
  • PipShowResult.Parse no longer throws when a License: line has no Location: line after it.

Testing

  • New headless UI tests (PythonPackagesDialogTests) open the real dialog over a substituted venv runner and type into the search box:
    • TypingInSearch_WhenPackageDetailsFailToLoad_DoesNotCrash: pip show throws FileNotFoundException. On the old code the exception is rethrown on the dispatcher and fails the test. It passes with the fix.
    • TypingInSearch_LoadsOnePackagesDetailsAtATime: on the old code more than one detail load ran at once. With the fix, at most one runs at a time.
  • New unit tests: PipIndexResultTests and two extra PipShowResultsTests cases (license without location, location before license).
  • StabilityMatrix.UITests: 21/21 passed. StabilityMatrix.Tests: all passed except the TestLicenseUrl / TestPreviewImageUri checks, which need outbound network access that my test environment blocks (unrelated to this change).

Selecting a package loads its details (pip show / pip index) in a
fire-and-forget task with no exception handler, so any failure other than
a ProcessException was rethrown on the UI thread and took down the app.
Typing in the search box moves the selection on almost every keystroke,
starting one of these loads per keystroke, overlapping against the same
venv.

- Log failures of the details load instead of rethrowing them
- Load one package's details at a time and skip loads whose package is no
  longer selected
- Don't start a second load for an item that is already loading
- PipIndexResult.Parse returns no versions instead of throwing when the
  output has no "Available versions:" line
- PipShowResult.Parse no longer throws when "License:" has no following
  "Location:" line

Fixes LykosAI#693

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Python Packages /CRASH/

1 participant