Skip to content

[releases/2.3] service: Resolve the current user's Discovery Service on Windows - #1358

Draft
amstewart wants to merge 2 commits into
ni:releases/2.3from
amstewart:users/astewart/per-user-discovery
Draft

amstewart wants to merge 2 commits into
ni:releases/2.3from
amstewart:users/astewart/per-user-discovery

Conversation

@amstewart

@amstewart amstewart commented Nov 19, 2026 •

Copy link
Copy Markdown

What does this Pull Request accomplish?

Backports per-user Discovery Service resolution to the releases/2.3 line, the last SDK line with its own copy of the Discovery client; SDK 3.x gets it from ni-apis-python. On Windows, Discovery now runs one instance per user, publishes its key file under %LOCALAPPDATA%\National Instruments\MeasurementLink\Discovery\v1, and passes DISCOVERY_SERVICE_ADDRESS to the services it launches. The client looks in this order:

  1. DISCOVERY_SERVICE_ADDRESS (host:port).
  2. The key file for the cluster from NIDiscovery_ClusterId or ClusterId.
  3. The per-user key file under %LOCALAPPDATA%.
  4. The legacy %ProgramData% key file. A file without ProcessId comes from an older single-instance Discovery and is used as before. A file with ProcessId may belong to another user's compatibility instance, so the client starts this user's own instance first and uses it only as a fallback.

Key files may start with a UTF-8 BOM and carry ProcessId and StartTime; unknown fields are ignored.

Why should this Pull Request be merged?

Without it, a measurement plug-in built with SDK 2.3 and launched by one user's Discovery can register with another user's Discovery instance, or find none when compatibility mode is off. This is part of Nigel local service authentication (ADO user story AB#4168818, task AB#4173545). The same change for SDK 3.x is in ni/ni-apis-python (users/astewart/per-user-discovery), and the Discovery side is in review in ASW !1508010.

Compatibility policy for SDK clients, decided by the feature owner on 2026-11-19: the client keeps working indefinitely against a legacy single-instance Discovery, which step 4 provides.

Draft: awaiting the feature owner's review before it is marked ready.

What testing has been done?

  • poetry run pytest tests/unit/test_discovery_service_resolution.py tests/unit/test_discovery_client.py in packages/service: 41 passed. The new resolution tests cover the order, the BOM, ProcessId semantics and the legacy fallback.
  • ni-python-styleguide lint and mypy on the changed files: clean.
  • Not yet run: a live two-user run on Windows against a per-user Discovery (tracked in V-2 of the Nigel effort).

amstewart and others added 2 commits November 17, 2026 13:36
…on Windows

On Windows, the NI Discovery Service now runs one instance per user on
OS-assigned ports and publishes its key file under
%LOCALAPPDATA%\National Instruments\MeasurementLink\Discovery\v1. The
machine-wide %ProgramData% key file and fixed ports 42000/42001 are only
a best-effort compatibility endpoint claimed by whichever user's
instance starts first. This SDK read only the %ProgramData% key file, so
a measurement service launched by one user's Discovery Service could
register with another user's instance, and found nothing when
compatibility mode was off.

Resolve the Discovery Service in this order:

1. DISCOVERY_SERVICE_ADDRESS, which the Discovery Service sets for the
   services it launches (host:port).
2. The key file for the cluster selected by NIDiscovery_ClusterId or
   ClusterId, as the Discovery Service and the 3.x client do.
3. The per-user key file under %LOCALAPPDATA%.
4. The %ProgramData% key file. A file without ProcessId was written by
   an older Discovery Service and is used as before. A file with
   ProcessId belongs to a compatibility-mode instance that may be
   another user's, so the SDK starts this user's own instance first and
   falls back to it only if that instance does not start.

Key files may start with a UTF-8 byte order mark and carry ProcessId and
StartTime fields; unknown fields are ignored. Other platforms are
unchanged when DISCOVERY_SERVICE_ADDRESS is not set.

SDK 3.x gets the same change through ni.measurementlink.discovery.v1.client
(ni-apis-python).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…on-Windows platforms

The legacy key file directory is Windows-only and raises NotImplementedError elsewhere, which broke Discovery resolution on Linux. Treat it as absent there.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@amstewart

amstewart commented Nov 19, 2026 •

Copy link
Copy Markdown
Author

@bkeryan @nick-beer

So my understanding here is that new development of the measurement-plugin-python repo is happening on the main ref (v3.x). And that 3.x gets its Discovery behavior from a package in the ni-apis-python project. So changing the client code for discovering a per-user Discovery Service should only be necessary in the ni-apis-python code here.

But this project has a v2.3 stable branch with its own discovery code (this PR), which I guess was outsourced in later releases. I see several v2.X release-candidate tags that looks like we're considering new v2 releases. But none of them seem to have made it to maturity.

So do we need to keep this backport to 2.3, because its the latest v2 release branch? Or can we drop it and say that all measurement-plugin clients should use the v3 release (which gets its discovery ode from ni-apis-python)?

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.

1 participant