Skip to content

Commit

Permalink
Add log warn when request is cancelled/interrupted
Browse files Browse the repository at this point in the history
  • Loading branch information
deluan committed Jul 27, 2022
1 parent cd5bce7 commit c0066eb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 4 additions & 0 deletions server/subsonic/api.go
Expand Up @@ -192,6 +192,10 @@ func h(r chi.Router, path string, f handler) {
sendError(w, r, err)
return
}
if r.Context().Err() != nil {
log.Warn("Request was interrupted", "path", path, r.Context().Err())
return
}
if res != nil {
sendResponse(w, r, res)
}
Expand Down
14 changes: 11 additions & 3 deletions server/subsonic/searching.go
Expand Up @@ -60,10 +60,14 @@ func doSearch[T any](ctx context.Context, wg *sync.WaitGroup, s searchFunc[T], q
}
done := make(chan struct{})
go func() {
typ := reflect.TypeOf(res).String()
var err error
start := time.Now()
res, err = s(q, offset, size)
if err != nil {
log.Error(ctx, "Error searching "+reflect.TypeOf(res).String(), err)
log.Error(ctx, "Error searching "+typ, err)
} else {
log.Trace(ctx, "Search for "+typ+" completed", "elapsedTime", time.Since(start))
}
done <- struct{}{}
}()
Expand All @@ -85,8 +89,12 @@ func (c *SearchingController) searchAll(r *http.Request, sp *searchParams) (medi
go func() { artists = doSearch(ctx, wg, c.ds.Artist(ctx).Search, q, sp.artistOffset, sp.artistCount) }()
wg.Wait()

log.Debug(ctx, fmt.Sprintf("Search resulted in %d songs, %d albums and %d artists",
len(mediaFiles), len(albums), len(artists)), "query", sp.query, "elapsedTime", time.Since(start))
if ctx.Err() == nil {
log.Debug(ctx, fmt.Sprintf("Search resulted in %d songs, %d albums and %d artists",
len(mediaFiles), len(albums), len(artists)), "query", sp.query, "elapsedTime", time.Since(start))
} else {
log.Warn(ctx, "Search was interrupted", ctx.Err(), "query", sp.query, "elapsedTime", time.Since(start))
}
return mediaFiles, albums, artists
}

Expand Down

0 comments on commit c0066eb

Please sign in to comment.