sourcegraph/thyme

getting nil pointer dereference on `thyme show -w stats` (macOS)

Closed this issue · 18 comments

I'm using GO version 1.7, and I got SIGSEGV when trying to exectute thyme show -i thyme.json -w stats > thyme.html. I'm not sure if 1.7 is causing the issue though.

Thanks!

Here are the details:

applefreak:~/ $ thyme show -i thyme.json -w stats > thyme.html                                     [11:34:25]
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0xa9f95]

goroutine 1 [running]:
panic(0x17f600, 0xc420010070)
    /usr/local/go/src/runtime/panic.go:500 +0x1a1
github.com/sourcegraph/thyme.Stats.func1(0x0, 0xc4202ed860, 0x9cb)
    /Users/applefreak/go/src/github.com/sourcegraph/thyme/show.go:17 +0x5
github.com/sourcegraph/thyme.NewTimeline(0xc4200a8420, 0x1c1c28, 0xc4202edc48)
    /Users/applefreak/go/src/github.com/sourcegraph/thyme/show.go:142 +0x39e
github.com/sourcegraph/thyme.Stats(0xc4200a8420, 0x5, 0x1aa813)
    /Users/applefreak/go/src/github.com/sourcegraph/thyme/show.go:17 +0x3b
main.(*ShowCmd).Execute(0x278180, 0xc4200ba640, 0x0, 0x5, 0x0, 0x0)
    /Users/applefreak/go/src/github.com/sourcegraph/thyme/cmd/thyme/main.go:114 +0x44b
github.com/jessevdk/go-flags.(*Parser).ParseArgs(0xc4200d6000, 0xc42000a130, 0x5, 0x5, 0x1, 0x0, 0x1b3201, 0xc4200001a0, 0x0)
    /Users/applefreak/go/src/github.com/jessevdk/go-flags/parser.go:314 +0x8e6
github.com/jessevdk/go-flags.(*Parser).Parse(0xc4200d6000, 0x0, 0x0, 0x0, 0x0, 0x0)
    /Users/applefreak/go/src/github.com/jessevdk/go-flags/parser.go:185 +0x74
main.main.func1(0x0, 0x32c4)
    /Users/applefreak/go/src/github.com/sourcegraph/thyme/cmd/thyme/main.go:141 +0x2d
main.main()
    /Users/applefreak/go/src/github.com/sourcegraph/thyme/cmd/thyme/main.go:148 +0x31

Got it, it looks like the issue is that the w *Window passed to the anonymous function here is nil.

Would you be able to post the thyme.json or send it to me privately? Feel free to sanitize the window name values in it. I just need the structure of the file.

@beyang I sent you an email with my thyme.json. Thank you for noting the problem!

Gui13 commented

Got the same issue here on Linux Ubuntu 16.04. I plussed.

go version go1.6.3 linux/amd64

Hi, same issue here. Linux Ubuntu 16.04, GO 1.7

I tracked down my issue, with same symptoms to be that the ID in "Active"-attribute was NOT in the list of "Windows". This happened once during half-a-day session. Removing the wrong snapshot from the array created the html-file correctly.

Basically a binary search / bisect will help you find the erroneous snapshot, e.g. starting with 0:200 interval.

echo '{ "Snapshots": [' > test.json && cat thyme.json | jq '. | .Snapshots | .[0:200]' >> test.json && echo ']}' >> test.json && thyme show -i test.json -w stats > thyme.html

The Active value in most of my snapshots is zero but there are no ID's of zero. I don't see any error output from the "thyme track" call.

MacOS 10.9.5
Go version 1.6.

thyme show -i thyme.json outputs a text file, but with -w stats it errors out.

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0x4bd9e0]

goroutine 1 [running]:
panic(0x5f69e0, 0xc82000e0f0)
    /usr/lib/go-1.6/src/runtime/panic.go:481 +0x3e6
github.com/sourcegraph/thyme.Stats.func1(0x0, 0xc820069618, 0x1c770c8)
    /home/millette/gocode/src/github.com/sourcegraph/thyme/show.go:17 +0x20
github.com/sourcegraph/thyme.NewTimeline(0xc8200ae540, 0x69a658, 0xc8200ae540)
    /home/millette/gocode/src/github.com/sourcegraph/thyme/show.go:142 +0x3d8
github.com/sourcegraph/thyme.Stats(0xc8200ae540, 0x0, 0x0)
    /home/millette/gocode/src/github.com/sourcegraph/thyme/show.go:17 +0x46
main.(*ShowCmd).Execute(0x758400, 0xc8200b4730, 0x0, 0x5, 0x0, 0x0)
    /home/millette/gocode/src/github.com/sourcegraph/thyme/cmd/thyme/main.go:114 +0x59e
github.com/jessevdk/go-flags.(*Parser).ParseArgs(0xc8200d0000, 0xc82000a0d0, 0x5, 0x5, 0x0, 0x0, 0x0, 0x0, 0x0)
    /home/millette/gocode/src/github.com/jessevdk/go-flags/parser.go:314 +0xa83
github.com/jessevdk/go-flags.(*Parser).Parse(0xc8200d0000, 0x0, 0x0, 0x0, 0x0, 0x0)
    /home/millette/gocode/src/github.com/jessevdk/go-flags/parser.go:185 +0x9b
main.main.func1(0x0, 0x0)
    /home/millette/gocode/src/github.com/sourcegraph/thyme/cmd/thyme/main.go:141 +0x2f
main.main()
    /home/millette/gocode/src/github.com/sourcegraph/thyme/cmd/thyme/main.go:148 +0x23

But I'm on Debian GNU/Linux. It worked a few times but it won't generate html anymore.

Yep, I have the same issue.

┬─[william@fillory:~/Projects/thyme/data]─[04:33:10 PM]
╰─>$ thyme show -i 20160817.json -w stats
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0x4bd9e0]

goroutine 1 [running]:
panic(0x5f69e0, 0xc820012100)
    /usr/lib/go/src/runtime/panic.go:481 +0x3e6
github.com/sourcegraph/thyme.Stats.func1(0x0, 0xc8200a7608, 0x1a0155e)
    /home/william/go/src/github.com/sourcegraph/thyme/show.go:17 +0x20
github.com/sourcegraph/thyme.NewTimeline(0xc8200b03e0, 0x69a658, 0xc8200b03e0)
    /home/william/go/src/github.com/sourcegraph/thyme/show.go:142 +0x3d8
github.com/sourcegraph/thyme.Stats(0xc8200b03e0, 0x0, 0x0)
    /home/william/go/src/github.com/sourcegraph/thyme/show.go:17 +0x46
main.(*ShowCmd).Execute(0x758400, 0xc8200b2460, 0x0, 0x5, 0x0, 0x0)
    /home/william/go/src/github.com/sourcegraph/thyme/cmd/thyme/main.go:114 +0x59e
github.com/jessevdk/go-flags.(*Parser).ParseArgs(0xc8200d2000, 0xc82000a130, 0x5, 0x5, 0x0, 0x0, 0x0, 0x0, 0x0)
    /home/william/go/src/github.com/jessevdk/go-flags/parser.go:314 +0xa83
github.com/jessevdk/go-flags.(*Parser).Parse(0xc8200d2000, 0x0, 0x0, 0x0, 0x0, 0x0)
    /home/william/go/src/github.com/jessevdk/go-flags/parser.go:185 +0x9b
main.main.func1(0x0, 0x0)
    /home/william/go/src/github.com/sourcegraph/thyme/cmd/thyme/main.go:141 +0x2f
main.main()
    /home/william/go/src/github.com/sourcegraph/thyme/cmd/thyme/main.go:148 +0x23

Same issue with Mac 10.11.6 and Go1.6

Gui13 commented

@beyang Not just Mac!! I have the issue on Linux too, and it is simply due to an active window ID not being in the list of windows in the same record (as @TeeeJay said)

This could be fixed by a simple check to see if the ID is present, and skip the record if not.

Also, for what is worth, I'm using a multi-display setup (laptop and external dock and screen).

same issue on windows 10 AU:

$ thyme show -i thyme.json -w stats > thyme.html
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x8 pc=0x4b3a35]

goroutine 1 [running]:
panic(0x59eb60, 0xc0420040c0)
        C:/tools/Go/src/runtime/panic.go:500 +0x1af
github.com/sourcegraph/thyme.Stats.func1(0x0, 0xc04202d858, 0x0)
        C:/tools/Go/src/github.com/sourcegraph/thyme/show.go:17 +0x5
github.com/sourcegraph/thyme.NewTimeline(0xc04200aee0, 0x5e4df8, 0xc04202dc40)
        C:/tools/Go/src/github.com/sourcegraph/thyme/show.go:142 +0x3a5
github.com/sourcegraph/thyme.Stats(0xc04200aee0, 0x5, 0x5cb2f8)
        C:/tools/Go/src/github.com/sourcegraph/thyme/show.go:17 +0x42
main.(*ShowCmd).Execute(0x6a3680, 0xc04200e690, 0x0, 0x5, 0x0, 0x0)
        C:/tools/Go/src/github.com/sourcegraph/thyme/cmd/thyme/main.go:114 +0x452
github.com/jessevdk/go-flags.(*Parser).ParseArgs(0xc0420104e0, 0xc042010250, 0x5, 0x5, 0x1, 0x0, 0x5d5101, 0xc04201a000, 0x0)
        C:/tools/Go/src/github.com/jessevdk/go-flags/parser.go:314 +0x8e3
github.com/jessevdk/go-flags.(*Parser).Parse(0xc0420104e0, 0x0, 0x0, 0x0, 0x0, 0x0)
        C:/tools/Go/src/github.com/jessevdk/go-flags/parser.go:185 +0x7b
main.main.func1(0x0, 0x40230b)
        C:/tools/Go/src/github.com/sourcegraph/thyme/cmd/thyme/main.go:141 +0x34
main.main()
        C:/tools/Go/src/github.com/sourcegraph/thyme/cmd/thyme/main.go:148 +0x38

Go version: go version go1.7 windows/amd64

Thanks for the bug report! I think this should be fixed by the above PR. Can you go get -u github.com/sourcegraph/thyme/cmd/thyme and try again? Re-open if still an issue.

That PR completely fixed it for me! Nicely Done!

Thanks @howeyc!

fixed for me too! thanks

@beyang This did fix the crashing. However, the vast majority of my 'Active' ID's are still zero.

When I run the AppleScript directly it seems to be working fine and returning (via a log command) an active window ID. I don't know go, so I'm not sure where else the issue might be.

@Bleyddyn can you post the output of the AppleScript?

@beyang There's too much private stuff in there for me to post it all, but here are a couple of things that look like they might be issues:

tell application "System Events"
    get name of application process "X11.bin"
        --> "X11.bin"
    get id of application process "X11.bin"
        --> 16318351
end tell
(*PROCESS 16318351:X11.bin*)
tell application "XQuartz"
    count every window of current application
        --> error number -1708
end tell
tell application "System Events"
    get name of application process "Python"
        --> "Python"
    get id of application process "Python"
        --> 492225871
end tell
(*PROCESS 492225871:Python*)
tell application "Python"
    count every window of current application
    count every window of current application
    count every window of current application
    count every window of current application
    count every window of current application
    count every window of current application
    count every window of current application
end tell

If I try to run the second AppleScript, the one that gets the frontmost window of the active application, it errors out if XQuartz is the foreground app:

tell application "System Events"
    get application process 1 whose frontmost = true
        --> application process "X11.bin"
    get name of application process "X11.bin"
        --> "X11.bin"
end tell
tell application "XQuartz"
    get every window
        --> error number -1708
end tell
tell application "System Events"
    get id of application process "X11.bin"
        --> 16318351
    get name of window 1 of application process "X11.bin"
        --> error number -1719 from window 1 of application process "X11.bin"
Result:
error "System Events got an error: Can’t get window 1 of application process \"X11.bin\". Invalid index." number -1719 from window 1 of application process "X11.bin"

I added a block of code to catch applications that don't support the 'count windows' Apple Event, which prevents the error, but I'm not sure what effect it would have when called from Go. I'm not sure what's up with the Python application. That's actually being launched via iPython notebook.

try
    tell application procName
        count of windows
    end tell
on error e
    -- If this errors out then no scripting is possible
    return
end try