[GH-ISSUE #2970] ollama run does not support tee #48336

Closed
opened 2026-04-28 07:48:17 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @DarkenedOrigins on GitHub (Mar 7, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/2970

~$ ollama run phi | tee llms/out.txt
>>> Error getting size: inappropriate ioctl for device
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x9ad54e]

goroutine 1 [running]:
github.com/jmorganca/ollama/readline.(*Buffer).IsEmpty(...)
        /go/src/github.com/jmorganca/ollama/readline/buffer.go:309
github.com/jmorganca/ollama/readline.(*Instance).Readline(0xc00058a160)
        /go/src/github.com/jmorganca/ollama/readline/readline.go:100 +0x20e
github.com/jmorganca/ollama/cmd.generateInteractive(0xc00045b200, {{0x7ffcd3b32552, 0x3}, {0x0, 0x0}, {0x0, 0x0}, {0x1184c8c0, 0x0, 0x0}, ...})
        /go/src/github.com/jmorganca/ollama/cmd/interactive.go:185 +0x1cf
github.com/jmorganca/ollama/cmd.RunHandler(0xc00045b200, {0xc00044d020, 0x1, 0x1})
        /go/src/github.com/jmorganca/ollama/cmd/cmd.go:212 +0x6c5
github.com/spf13/cobra.(*Command).execute(0xc00045b200, {0xc00044cff0, 0x1, 0x1})
        /root/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:940 +0x87c
github.com/spf13/cobra.(*Command).ExecuteC(0xc00045a900)
        /root/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:1068 +0x3a5
github.com/spf13/cobra.(*Command).Execute(...)
        /root/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:992
github.com/spf13/cobra.(*Command).ExecuteContext(...)
        /root/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:985
main.main()
        /go/src/github.com/jmorganca/ollama/main.go:11 +0x4d

I tried using tee to save the output but this caused a segfault.
Seems like the issue might be here?
0ded7fdc4b/readline/readline.go (L89)
NewBuffer can be returning nil and there is no check for this.
0ded7fdc4b/readline/buffer.go (L23)
this is where NewBuffer is returning the nil
I do not understand why term.Getsize would be failing?

Note: it works perfectly when I do not use tee

Originally created by @DarkenedOrigins on GitHub (Mar 7, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/2970 ``` ~$ ollama run phi | tee llms/out.txt >>> Error getting size: inappropriate ioctl for device panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x9ad54e] goroutine 1 [running]: github.com/jmorganca/ollama/readline.(*Buffer).IsEmpty(...) /go/src/github.com/jmorganca/ollama/readline/buffer.go:309 github.com/jmorganca/ollama/readline.(*Instance).Readline(0xc00058a160) /go/src/github.com/jmorganca/ollama/readline/readline.go:100 +0x20e github.com/jmorganca/ollama/cmd.generateInteractive(0xc00045b200, {{0x7ffcd3b32552, 0x3}, {0x0, 0x0}, {0x0, 0x0}, {0x1184c8c0, 0x0, 0x0}, ...}) /go/src/github.com/jmorganca/ollama/cmd/interactive.go:185 +0x1cf github.com/jmorganca/ollama/cmd.RunHandler(0xc00045b200, {0xc00044d020, 0x1, 0x1}) /go/src/github.com/jmorganca/ollama/cmd/cmd.go:212 +0x6c5 github.com/spf13/cobra.(*Command).execute(0xc00045b200, {0xc00044cff0, 0x1, 0x1}) /root/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:940 +0x87c github.com/spf13/cobra.(*Command).ExecuteC(0xc00045a900) /root/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:1068 +0x3a5 github.com/spf13/cobra.(*Command).Execute(...) /root/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:992 github.com/spf13/cobra.(*Command).ExecuteContext(...) /root/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:985 main.main() /go/src/github.com/jmorganca/ollama/main.go:11 +0x4d ``` I tried using tee to save the output but this caused a segfault. Seems like the issue might be here? https://github.com/ollama/ollama/blob/0ded7fdc4b33801fd0115656927b6097f800c544/readline/readline.go#L89 NewBuffer can be returning nil and there is no check for this. https://github.com/ollama/ollama/blob/0ded7fdc4b33801fd0115656927b6097f800c544/readline/buffer.go#L23 this is where NewBuffer is returning the nil I do not understand why term.Getsize would be failing? Note: it works perfectly when I do not use tee
GiteaMirror added the good first issuebug labels 2026-04-28 07:48:17 -05:00
Author
Owner

@powerfooI commented on GitHub (Mar 7, 2024):

Maybe the redirection changed the real file descriptor of os.Stdout.Fd(), which finally caused term.Getsize failed. I have some ideas to solve it, can I work on this?

<!-- gh-comment-id:1983401357 --> @powerfooI commented on GitHub (Mar 7, 2024): Maybe the redirection changed the real file descriptor of `os.Stdout.Fd()`, which finally caused term.Getsize failed. I have some ideas to solve it, can I work on this?
Author
Owner

@mxyng commented on GitHub (Mar 7, 2024):

What platform are you using? I'm not able to reproduce this on macOS Sonoma, Ubuntu 22.04, or Windows 11

Edit: nevermind, I see what you're doing. You're trying to redirect while in interactive mode. It's not really something ollama supports though to avoid a panic, it's sufficient to have default values, probably width=80, height=24

<!-- gh-comment-id:1984259521 --> @mxyng commented on GitHub (Mar 7, 2024): What platform are you using? I'm not able to reproduce this on macOS Sonoma, Ubuntu 22.04, or Windows 11 Edit: nevermind, I see what you're doing. You're trying to redirect while in interactive mode. It's not really something ollama supports though to avoid a panic, it's sufficient to have default values, probably width=80, height=24
Author
Owner

@DarkenedOrigins commented on GitHub (Mar 7, 2024):

Windows 10 wsl2 using windows terminal. The os is Ubuntu 22.04 lts

On Thu, Mar 7, 2024, 14:20 Michael Yang @.***> wrote:

What platform are you using? I'm not able to reproduce this on macOS
Sonoma, Ubuntu 22.04, or Windows 11


Reply to this email directly, view it on GitHub
https://github.com/ollama/ollama/issues/2970#issuecomment-1984259521,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AITDOS6Q27ADH3FRRMFJJJLYXC4ZDAVCNFSM6AAAAABEKI23VKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOBUGI2TSNJSGE
.
You are receiving this because you authored the thread.Message ID:
@.***>

<!-- gh-comment-id:1984462414 --> @DarkenedOrigins commented on GitHub (Mar 7, 2024): Windows 10 wsl2 using windows terminal. The os is Ubuntu 22.04 lts On Thu, Mar 7, 2024, 14:20 Michael Yang ***@***.***> wrote: > What platform are you using? I'm not able to reproduce this on macOS > Sonoma, Ubuntu 22.04, or Windows 11 > > — > Reply to this email directly, view it on GitHub > <https://github.com/ollama/ollama/issues/2970#issuecomment-1984259521>, > or unsubscribe > <https://github.com/notifications/unsubscribe-auth/AITDOS6Q27ADH3FRRMFJJJLYXC4ZDAVCNFSM6AAAAABEKI23VKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOBUGI2TSNJSGE> > . > You are receiving this because you authored the thread.Message ID: > ***@***.***> >
Author
Owner

@DarkenedOrigins commented on GitHub (Mar 8, 2024):

made a suggestion to pr #2983

<!-- gh-comment-id:1985019556 --> @DarkenedOrigins commented on GitHub (Mar 8, 2024): made a suggestion to pr #2983
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#48336