hammond icon indicating copy to clipboard operation
hammond copied to clipboard

"runtime error: invalid memory address or nil pointer dereference" after moving files

Open AlphaJack opened this issue 4 years ago • 4 comments

Please complete the following information

  • Installation Type: native
  • Have you tried using the latest docker image / code base: yes

Describe the bug Hi, I am trying to package hammond for the AUR, but I am unable to make it work after splitting files in various paths:

  • /etc/hammond.conf as environmental file
  • /usr/bin/hammond as main executable
  • /usr/share/hammond/ as static assets location
  • /var/lib/hammond/ as the only writable location (e.g. database file)

I start hammond as a service with the following environmental variables:

CONFIG=/var/lib/hammond
DATA=/usr/share/hammond
PORT=3000
JWT_SECRET="XXXXXX"

When I visit http://127.0.0.1:3000 I get the following service error:

hammond[163941]: [GIN-debug] Listening and serving HTTP on :3000
hammond[163941]: 2021/06/05 19:26:40 Config Dir:  /usr/share/hammond
hammond[163941]: 2021/06/05 19:26:40 Assets Dir:  /var/lib/hammond
hammond[163941]: 2021/06/05 19:26:50 [Recovery] 2021/06/05 - 19:26:50 panic recovered:
hammond[163941]: GET / HTTP/1.1                                                                            
hammond[163941]: Host: 127.0.0.1:3000                                                                      
hammond[163941]: Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8        
hammond[163941]: Accept-Encoding: gzip, deflate                                                            
hammond[163941]: Accept-Language: en-US,en;q=0.5                                                           
hammond[163941]: Connection: keep-alive                                                                    
hammond[163941]: Cookie: session_id=a7de39dc9fbf6dd819b4382adc29dec7bc2af2c8                               
hammond[163941]: Dnt: 1                                                                                    
hammond[163941]: Upgrade-Insecure-Requests: 1                                                              
hammond[163941]: User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Firefox/78.0            
hammond[163941]:                                                                                           
hammond[163941]: runtime error: invalid memory address or nil pointer dereference                          
hammond[163941]: /usr/lib/go/src/runtime/panic.go:212 (0x43ca7a)                                           
hammond[163941]:        panicmem: panic(memoryError)                                                       
hammond[163941]: /usr/lib/go/src/runtime/signal_unix.go:734 (0x455432)
hammond[163941]:        sigpanic: panicmem()
hammond[163941]: /home/jack/go/pkg/mod/gorm.io/[email protected]/gorm.go:340 (0x766886)
hammond[163941]: /home/jack/go/pkg/mod/gorm.io/[email protected]/chainable_api.go:224 (0x75dd6e)
hammond[163941]: /home/jack/go/pkg/mod/gorm.io/[email protected]/finisher_api.go:117 (0x75f2c8)
hammond[163941]: /tmp/makepkg/hammond-git/src/hammond/server/db/dbfunctions.go:257 (0x7f98cc)
hammond[163941]:        GetOrCreateSetting: result := DB.First(&setting)
hammond[163941]: /tmp/makepkg/hammond-git/src/hammond/server/main.go:62 (0x9d9dc5)
hammond[163941]:        setupSettings.func1: setting := db.GetOrCreateSetting()
hammond[163941]: /home/jack/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:165 (0x9b2839)
hammond[163941]: /home/jack/go/pkg/mod/github.com/gin-gonic/[email protected]/recovery.go:99 (0x9b2820)
hammond[163941]: /home/jack/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:165 (0x9b1913)
hammond[163941]: /home/jack/go/pkg/mod/github.com/gin-gonic/[email protected]/logger.go:241 (0x9b18d2)
hammond[163941]: /home/jack/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:165 (0x9a85c8)
hammond[163941]: /home/jack/go/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:525 (0x9a85af)
hammond[163941]: /home/jack/go/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:518 (0x9a82e6)
hammond[163941]: /home/jack/go/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:445 (0x9a7b9b)
hammond[163941]: /usr/lib/go/src/net/http/server.go:2887 (0x6b6be2)
hammond[163941]:        serverHandler.ServeHTTP: handler.ServeHTTP(rw, req)
hammond[163941]: /usr/lib/go/src/net/http/server.go:1952 (0x6b200c)
hammond[163941]:        (*conn).serve: serverHandler{c.server}.ServeHTTP(w, w.req)
hammond[163941]: /usr/lib/go/src/runtime/asm_amd64.s:1371 (0x474d60)
hammond[163941]:        goexit: BYTE    $0x90   // NOP
hammond[163941]:
hammond[163941]: [GIN] 2021/06/05 - 19:26:50 | 500 |    3.923481ms |       127.0.0.1 | GET      "/"

The browser of course gets an empty page and a 500 error.

To Reproduce I have built the program in the /tmp/makepkg/hammond-git/src/ folder following the source installation steps. If I launch the hammond executable as soon as it is built, without moving it (/tmp/makepkg/hammond-git/src/hammond/server/dist/hammond instead of /usr/bin/hammond), I only get a 404 error when I access http://127.0.0.1:3000, which makes me think it can now find some program file/library that /usr/bin/hammond is missing.

Questions

  1. Why are you saying to run mv -v dist/* /usr/local/bin/hammond if there is only a single file under dist (at least, for me)?
  2. Any plan to make hammond statically linked? Otherwise, what else should I copy from the build directory apart from the files under server/dist/ and ui/dist/?
  3. Am I setting my CONFIG and DATA variables correctly? If not, what do you mean by these terms?
  4. Are there other variables to configure, like HOST?

Additional information This would be the full file list of the package:

 /
├── etc
│   └── hammond.conf
├── usr
│   ├── bin
│   │   └── hammond
│   ├── lib
│   │   ├── systemd
│   │   │   └── system
│   │   │       └── hammond.service
│   │   ├── sysusers.d
│   │   │   └── hammond.conf
│   │   └── tmpfiles.d
│   │       └── hammond.conf
│   └── share
│       └── hammond
│           ├── css
│           │   ├── app.f7de76d5.css
│           │   ├── app.f7de76d5.css.map
│            |   [...]  
│           │   ├── chunk-vendors.4bd0e6af.css
│           │   └── chunk-vendors.4bd0e6af.css.map
│           ├── hammond.png
│           ├── index.html
│           └── js
│               ├── app-legacy.f1603146.js
│               ├── app-legacy.f1603146.js.map
│              [...]  
│               ├── chunk-vendors.06a1605f.js
│               └── chunk-vendors.06a1605f.js.map
└── var
    └── lib
        └── hammond

15 directories, 79 files

AlphaJack avatar Jun 05 '21 18:06 AlphaJack

Which OS (exact version) did you try this on? I will try to get test this on a VM maybe.

akhilrex avatar Jun 07 '21 10:06 akhilrex

Manjaro Linux, but I guess the problem would persist on both Arch Linux x64 and Arch Linux ARM

AlphaJack avatar Jun 07 '21 17:06 AlphaJack

I have not been able to make time to set it up. By any chance have you been able to solve this?

akhilrex avatar Jun 27 '21 08:06 akhilrex

I just tried forcing some flags in go build and the error seems gone, however I am now getting error 404:

hammond[51295]: [GIN-debug] Listening and serving HTTP on :3000
hammond[51295]: 2021/06/27 11:45:07 Config Dir:  /var/lib/hammond
hammond[51295]: 2021/06/27 11:45:07 Assets Dir:  /usr/share/hammond
hammond[51295]: [GIN] 2021/06/27 - 11:45:11 | 404 |     655.346µs |       127.0.0.1 | GET      "/"

The assets dir should contain index.html, hammond.png, css/ and js/? Because mine does so.
Is there a way to configure the host and port on program start, like CONFIG and DATA variables?

AlphaJack avatar Jun 27 '21 09:06 AlphaJack