[GH-ISSUE #5129] gpu destroys TMPDIR #49743

Closed
opened 2026-04-28 12:51:18 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @vt-alt on GitHub (Jun 19, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/5129

What is the issue?

When building ollama package for ALT Linux I noticed that %buildroot (directory where new binaries are installed) is disappeared after go test github.com/ollama/ollama/gpu. Our %buildroot (/usr/src/tmp/ollama-buildroot) is inside of TMPDIR (/usr/src/tmp).

I am not completely investigated the issue but this is extremely dangerous practice to delete directories you did not create. If it deletes %buildroot it may delete anything else such as homedir?

I see so suspicious code fragment in gpu/assets.go:

func Cleanup() {
        lock.Lock()
        defer lock.Unlock()
        runnersDir := envconfig.RunnersDir
        if payloadsDir != "" && runnersDir == "" && runtime.GOOS != "windows" {
                // We want to fully clean up the tmpdir parent of the payloads dir
                tmpDir := filepath.Clean(filepath.Join(payloadsDir, ".."))
                slog.Debug("cleaning up", "dir", tmpDir)
                err := os.RemoveAll(tmpDir)
                if err != nil {
                        // On windows, if we remove too quickly the llama.dll may still be in-use and fail to remove
                        time.Sleep(1000 * time.Millisecond)
                        err = os.RemoveAll(tmpDir)
                        if err != nil {
                                slog.Warn("failed to clean up", "dir", tmpDir, "err", err)
                        }
                }
        }
}

So it tries to delete parent of TMPDIR? What if HOME or other important directories are there?

Please make it not delete directories or files it did not create

OS

Linux

GPU

Other

CPU

Intel

Ollama version

0.1.44

Originally created by @vt-alt on GitHub (Jun 19, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/5129 ### What is the issue? When building ollama package for ALT Linux I noticed that %buildroot (directory where new binaries are installed) is disappeared after `go test github.com/ollama/ollama/gpu`. Our `%buildroot` (`/usr/src/tmp/ollama-buildroot`) is inside of `TMPDIR` (`/usr/src/tmp`). I am not completely investigated the issue but this is extremely dangerous practice to delete directories you did not create. If it deletes %buildroot it may delete anything else such as homedir? I see so suspicious code fragment in `gpu/assets.go`: ```go func Cleanup() { lock.Lock() defer lock.Unlock() runnersDir := envconfig.RunnersDir if payloadsDir != "" && runnersDir == "" && runtime.GOOS != "windows" { // We want to fully clean up the tmpdir parent of the payloads dir tmpDir := filepath.Clean(filepath.Join(payloadsDir, "..")) slog.Debug("cleaning up", "dir", tmpDir) err := os.RemoveAll(tmpDir) if err != nil { // On windows, if we remove too quickly the llama.dll may still be in-use and fail to remove time.Sleep(1000 * time.Millisecond) err = os.RemoveAll(tmpDir) if err != nil { slog.Warn("failed to clean up", "dir", tmpDir, "err", err) } } } } ``` So it tries to delete parent of TMPDIR? What if HOME or other important directories are there? Please make it not delete directories or files it did not create ### OS Linux ### GPU Other ### CPU Intel ### Ollama version 0.1.44
GiteaMirror added the bug label 2026-04-28 12:51:18 -05:00
Author
Owner

@vt-alt commented on GitHub (Jun 19, 2024):

Example how it looks

builder@x86_64-p11:~/RPM/BUILD/ollama-0.1.44$ echo $TMPDIR
/usr/src/tmp
builder@x86_64-p11:~/RPM/BUILD/ollama-0.1.44$ /usr/src/tmp/ollama-buildroot/usr/bin/ollama --version
Warning: could not connect to a running Ollama instance
Warning: client version is 0.1.44
builder@x86_64-p11:~/RPM/BUILD/ollama-0.1.44$ go test github.com/ollama/ollama/gpu
^[[A^[[Aok      github.com/ollama/ollama/gpu    0.016s
builder@x86_64-p11:~/RPM/BUILD/ollama-0.1.44$ /usr/src/tmp/ollama-buildroot/usr/bin/ollama --version
-bash: /usr/src/tmp/ollama-buildroot/usr/bin/ollama: No such file or directory
builder@x86_64-p11:~/RPM/BUILD/ollama-0.1.44$

Please do not delete user's data you did not create.

<!-- gh-comment-id:2177467870 --> @vt-alt commented on GitHub (Jun 19, 2024): Example how it looks ``` builder@x86_64-p11:~/RPM/BUILD/ollama-0.1.44$ echo $TMPDIR /usr/src/tmp builder@x86_64-p11:~/RPM/BUILD/ollama-0.1.44$ /usr/src/tmp/ollama-buildroot/usr/bin/ollama --version Warning: could not connect to a running Ollama instance Warning: client version is 0.1.44 builder@x86_64-p11:~/RPM/BUILD/ollama-0.1.44$ go test github.com/ollama/ollama/gpu ^[[A^[[Aok github.com/ollama/ollama/gpu 0.016s builder@x86_64-p11:~/RPM/BUILD/ollama-0.1.44$ /usr/src/tmp/ollama-buildroot/usr/bin/ollama --version -bash: /usr/src/tmp/ollama-buildroot/usr/bin/ollama: No such file or directory builder@x86_64-p11:~/RPM/BUILD/ollama-0.1.44$ ``` Please do not delete user's data you did not create.
Author
Owner

@vt-alt commented on GitHub (Jun 25, 2024):

@joshyan1 Thanks much for the fix! Tested it to be OK.

<!-- gh-comment-id:2188159771 --> @vt-alt commented on GitHub (Jun 25, 2024): @joshyan1 Thanks much for the fix! Tested it to be OK.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#49743