Skip to content

nvml: return ERROR_UNINITIALIZED from Shutdown when nothing was loaded - #206

Merged
tariq1890 merged 1 commit into
NVIDIA:mainfrom
lenamonj:shutdown-uninitialized
Oct 6, 2026
Merged

tariq1890 merged 1 commit into
NVIDIA:mainfrom
lenamonj:shutdown-uninitialized

Conversation

@lenamonj

@lenamonj lenamonj commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Shutdown() called nvmlShutdown() unconditionally. On Linux the bindings link with -Wl,--unresolved-symbols=ignore-in-object-files, so that symbol resolves only after Init() opens libnvidia-ml.so.1; a Shutdown() when Init() was never called, or could not open the library, took the process down with symbol lookup error: undefined symbol: nvmlShutdown.

Shutdown() now returns ERROR_UNINITIALIZED, the return nvml.h documents for a shutdown without a prior initialization, when the library holds no reference. That check, nvmlShutdown() and the release run under the library's lock, so a second Shutdown() cannot reach nvmlShutdown() after the first has closed the library. Two tests cover the never-loaded and failed-Init() paths; each aborts the test binary on main. make build and make test pass; gofmt and go vet are clean.

@lenamonj
lenamonj force-pushed the shutdown-uninitialized branch from 9e52146 to f6feef9 Compare September 13, 2026 17:57
@rajathagasthya

Copy link
Copy Markdown
Contributor

/ok-to-test f6feef9

@lenamonj
lenamonj force-pushed the shutdown-uninitialized branch from f6feef9 to 2abe1fe Compare September 17, 2026 02:55
@lenamonj

Copy link
Copy Markdown
Contributor Author

The commit is now signed and rebased onto current main. The explanatory comments in init.go and the test are dropped; nothing else changed.

devin-ai-integration[bot]

This comment was marked as resolved.

@lenamonj
lenamonj force-pushed the shutdown-uninitialized branch 2 times, most recently from 42ff3d6 to 31ea91f Compare September 19, 2026 00:42
Comment thread pkg/nvml/init_test.go Resolved
@tariq1890

Copy link
Copy Markdown
Contributor

@lenamonj Please squash the commit history

Shutdown() called nvmlShutdown() unconditionally. The bindings link with
-Wl,--unresolved-symbols=ignore-in-object-files, so that symbol resolves
only after Init() has opened libnvidia-ml.so.1; on a host without that
library, the Shutdown() a caller pairs with a failed Init() took the
process down with a symbol lookup error instead of returning. Shutdown()
now returns ERROR_UNINITIALIZED, the return nvml.h documents for a
shutdown without a prior initialization, when the library holds no
reference.

The check, the nvmlShutdown() call and the release of the reference run
under the library's lock, so a second Shutdown() cannot reach
nvmlShutdown() after the first has closed the library. close() keeps its
lock and delegates to closeLocked(), which Shutdown() calls with the lock
already held.

Signed-off-by: Jeff Lenamon <[email protected]>
@lenamonj
lenamonj force-pushed the shutdown-uninitialized branch from 4f76c27 to b8d53c7 Compare October 6, 2026 01:21
@lenamonj

lenamonj commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

Squashed to one commit, b8d53c7; same base and tree as before.

@tariq1890
tariq1890 merged commit 3715161 into NVIDIA:main Oct 6, 2026
5 checks passed
@lenamonj
lenamonj deleted the shutdown-uninitialized branch October 6, 2026 19:49
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.

3 participants