sentriz / gonic

music streaming server / free-software subsonic server API implementation
ircs://irc.libera.chat/#gonic
GNU General Public License v3.0
1.57k stars 112 forks source link

store full paths to playlist items in db, not track fkeys #54

Closed alex-phillips closed 1 year ago

alex-phillips commented 4 years ago

All other endpoints seem fine from what I can tell, but I get a failed CORS issue when attempting to retrieve getPlaylist.view endpoint.

sentriz commented 4 years ago

well that is very strange. can you show the output of curl -LD - "http://your.gonic/rest/getPlaylist.view" also to compare the output of a presumably working endpoint: curl -LD - "http://your.gonic/rest/ping.view"

alex-phillips commented 4 years ago

@sentriz so it's not a CORS issue after all, but that getPlaylist is returning a 502 Bad Gateway for some reason....

$ curl -LD - "https://gonic.example.com/rest/ping.view?f=json&c=CLIENT&v=1.15&u=USERNAME&s=S&t=TOKEN"
HTTP/2 200 
server: nginx/1.16.1
date: Thu, 09 Apr 2020 16:47:12 GMT
content-type: application/json
content-length: 94
access-control-allow-headers: Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization
access-control-allow-methods: POST, GET, OPTIONS, PUT, DELETE
access-control-allow-origin: *

{"subsonic-response":{"status":"ok","version":"1.9.0","type":"gonic","gonicVersion":"v0.8.4"}}

and

$ curl -LD - "https://gonic.example.com/rest/getPlaylist.view?f=json&c=CLIENT&v=1.15&u=USERNAME&s=S&t=TOKEN&id=23"
HTTP/2 502 
server: nginx/1.16.1
date: Thu, 09 Apr 2020 16:47:57 GMT
content-type: text/html
content-length: 157

<html>
<head><title>502 Bad Gateway</title></head>
<body>
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx/1.16.1</center>
</body>
</html>
alex-phillips commented 4 years ago

Update:

Error outputted fro m502 endpoint:

2020/04/09 16:49:07 http: panic serving 172.18.0.39:43586: runtime error: invalid memory address or nil pointer dereference
goroutine 29036 [running]:
net/http.(*conn).serve.func1(0xc0001dc0a0)
    /usr/local/go/src/net/http/server.go:1772 +0x139
panic(0x9ef660, 0xf14e30)
    /usr/local/go/src/runtime/panic.go:973 +0x3e3
go.senan.xyz/gonic/server/ctrlsubsonic/spec.NewTCTrackByFolder(0xc000715860, 0x0, 0xc000715860)
    /src/server/ctrlsubsonic/spec/construct_by_folder.go:49 +0xae
go.senan.xyz/gonic/server/ctrlsubsonic.(*Controller).ServeGetPlaylist(0xc000425c80, 0xc000175400, 0xc00010e480)
    /src/server/ctrlsubsonic/handlers_common.go:168 +0x763
go.senan.xyz/gonic/server/ctrlsubsonic.(*Controller).H.func1(0xb709a0, 0xc0001bc0a0, 0xc000175400)
    /src/server/ctrlsubsonic/ctrl.go:93 +0x33
net/http.HandlerFunc.ServeHTTP(0xc000421890, 0xb709a0, 0xc0001bc0a0, 0xc000175400)
    /usr/local/go/src/net/http/server.go:2012 +0x44
go.senan.xyz/gonic/server/ctrlsubsonic.(*Controller).WithUser.func1(0xb709a0, 0xc0001bc0a0, 0xc000174c00)
    /src/server/ctrlsubsonic/middleware.go:88 +0x513
net/http.HandlerFunc.ServeHTTP(0xc0001bc000, 0xb709a0, 0xc0001bc0a0, 0xc000174c00)
    /usr/local/go/src/net/http/server.go:2012 +0x44
go.senan.xyz/gonic/server/ctrlsubsonic.(*Controller).WithRequiredParams.func1(0xb709a0, 0xc0001bc0a0, 0xc000174c00)
    /src/server/ctrlsubsonic/middleware.go:52 +0x121
net/http.HandlerFunc.ServeHTTP(0xc00026a210, 0xb709a0, 0xc0001bc0a0, 0xc000174c00)
    /usr/local/go/src/net/http/server.go:2012 +0x44
go.senan.xyz/gonic/server/ctrlsubsonic.(*Controller).WithParams.func1(0xb709a0, 0xc0001bc0a0, 0xc000174700)
    /src/server/ctrlsubsonic/middleware.go:33 +0x17c
net/http.HandlerFunc.ServeHTTP(0xc0001bc020, 0xb709a0, 0xc0001bc0a0, 0xc000174700)
    /usr/local/go/src/net/http/server.go:2012 +0x44
go.senan.xyz/gonic/server/ctrlbase.(*Controller).WithCORS.func1(0xb709a0, 0xc0001bc0a0, 0xc000174700)
    /src/server/ctrlbase/ctrl.go:82 +0x300
net/http.HandlerFunc.ServeHTTP(0xc0001bc060, 0xb709a0, 0xc0001bc0a0, 0xc000174700)
    /usr/local/go/src/net/http/server.go:2012 +0x44
go.senan.xyz/gonic/server/ctrlbase.(*Controller).WithLogging.func1(0xb70ce0, 0xc00026c000, 0xc000174700)
    /src/server/ctrlbase/ctrl.go:65 +0x9d
net/http.HandlerFunc.ServeHTTP(0xc0001bc080, 0xb70ce0, 0xc00026c000, 0xc000174700)
    /usr/local/go/src/net/http/server.go:2012 +0x44
github.com/gorilla/mux.(*Router).ServeHTTP(0xc00002c0c0, 0xb70ce0, 0xc00026c000, 0xc000174000)
    /go/pkg/mod/github.com/gorilla/mux@v1.7.3/mux.go:212 +0xe2
net/http.serverHandler.ServeHTTP(0xc0004fe000, 0xb70ce0, 0xc00026c000, 0xc000174000)
    /usr/local/go/src/net/http/server.go:2807 +0xa3
net/http.(*conn).serve(0xc0001dc0a0, 0xb72260, 0xc000300200)
    /usr/local/go/src/net/http/server.go:1895 +0x86c
created by net/http.(*Server).Serve
    /usr/local/go/src/net/http/server.go:2933 +0x35c
sentriz commented 4 years ago

ouch. thanks for finding that. having a look now

alex-phillips commented 4 years ago

@sentriz I think it's because my playlists might be showing 0 as the song count. Not sure why, I'll try re-importing. But that might help narrow it down?

alex-phillips commented 4 years ago

@sentriz Ok, so my playlists are all populated now and it's working fine. Not sure how they got cleared out, but no more 502s.

sentriz commented 4 years ago

good to hear :) still trying to reproduce locally. if i do i'll push a fix for the future

alex-phillips commented 4 years ago

Great! Thanks again for the great project.

alex-phillips commented 4 years ago

@sentriz Just a thought - this could happen if a playlist includes a track filepath that may no longer exist in the library anymore. I.e., if I had MP3 of a track and it was on a playlist but I replaced that album with a FLAC version. Might be related?

sentriz commented 4 years ago

yeah just had a look. airsonic store full paths for playlists in their db. probably for good reason, like yours

djl commented 2 years ago

I might be running into this, too.

[... a few hundred folders here...]
2022/03/13 15:18:49 processing folder `/media/music/Alex Cameron/Oxy Music`
2022/03/13 15:18:49 finished scan in 4.91389s, +0/5376 tracks (0 err)
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x821c75]
goroutine 32 [running]:
go.senan.xyz/gonic/server/scanner.populateTrack(0xc0007fda60, 0xc00012fa40, 0xc0006b8600, {0xcc5ef0, 0xc00069fab0}, {0xc000783ba8, 0x15}, 0x1b4c8b3)
        /src/server/scanner/scanner.go:298 +0x175
go.senan.xyz/gonic/server/scanner.(*Scanner).populateTrackAndAlbumArtists(0xc000075680, 0xc0007fda60, 0xc0004ce000, 0x3, 0xc00012fa40, 0xc00012fa40, {0xc000783ba8, 0x15}, {0xc0003c5080, 0x39})
        /src/server/scanner/scanner.go:234 +0x705
go.senan.xyz/gonic/server/scanner.(*Scanner).scanDir(0xb81a06, 0xc0007fda60, 0xc0004ce000, {0xc00002c011, 0xc}, {0xc00044d860, 0x23})
        /src/server/scanner/scanner.go:185 +0x58a
go.senan.xyz/gonic/server/scanner.(*Scanner).scanCallback(0xc000075680, 0xc0004ce000, {0xc00002c011, 0xc00044d830}, {0xc00044d860, 0x1a}, {0xcb7928, 0xc00086cd80}, {0x0, 0x0})
        /src/server/scanner/scanner.go:134 +0x27e
go.senan.xyz/gonic/server/scanner.(*Scanner).ScanAndClean.func2({0xc00044d860, 0x23}, {0xcb7928, 0xc00086cd80}, {0x0, 0x0})
        /src/server/scanner/scanner.go:79 +0x6c
path/filepath.walkDir({0xc00044d860, 0x23}, {0xcb7928, 0xc00086cd80}, 0xc0007fdf40)
        /usr/local/go/src/path/filepath/path.go:386 +0x63
path/filepath.walkDir({0xc000481b00, 0x19}, {0xcb7928, 0xc0004fcbc0}, 0xc0007fdf40)
        /usr/local/go/src/path/filepath/path.go:405 +0x232
path/filepath.walkDir({0xc00002c011, 0xc}, {0xcb7960, 0xc000020010}, 0xc0007fdf40)
        /usr/local/go/src/path/filepath/path.go:405 +0x232
path/filepath.WalkDir({0xc00002c011, 0xc}, 0xc0004e7f40)
        /usr/local/go/src/path/filepath/path.go:469 +0xb0
go.senan.xyz/gonic/server/scanner.(*Scanner).ScanAndClean(0xc000075680, {0x0})
        /src/server/scanner/scanner.go:78 +0x838
go.senan.xyz/gonic/server/ctrlsubsonic.(*Controller).ServeStartScan.func1()
        /src/server/ctrlsubsonic/handlers_common.go:85 +0x28
created by go.senan.xyz/gonic/server/ctrlsubsonic.(*Controller).ServeStartScan
        /src/server/ctrlsubsonic/handlers_common.go:84 +0x65

If I move the directory out of the way, the scan will continue until it hits another problematic directory.

Unfortunately moving it back and restarting the scan doesn't fix the issue so I need to wipe the SQLite DB and restart from scratch. Not the worst thing in the world but with ~180,000 files, it's not a quick process 😄