diff --git a/log/log_test.go b/log/log_test.go
index 923ccec52..f11a2b491 100644
--- a/log/log_test.go
+++ b/log/log_test.go
@@ -92,7 +92,7 @@ var _ = Describe("Logger", func() {
 			Error("A crash happened")
 			Expect(hook.LastEntry().Message).To(Equal("A crash happened"))
 			// NOTE: This assertions breaks if the line number changes
-			Expect(hook.LastEntry().Data[" source"]).To(ContainSubstring("log_test.go:92"))
+			Expect(hook.LastEntry().Data[" source"]).To(ContainSubstring("/log/log_test.go:92"))
 		})
 	})
 
diff --git a/server/subsonic/middlewares.go b/server/subsonic/middlewares.go
index bbee7583d..161cddfd1 100644
--- a/server/subsonic/middlewares.go
+++ b/server/subsonic/middlewares.go
@@ -112,16 +112,17 @@ func getPlayer(players engine.Players) func(next http.Handler) http.Handler {
 					ctx = context.WithValue(ctx, "transcoding", *trc)
 				}
 				r = r.WithContext(ctx)
+
+				cookie := &http.Cookie{
+					Name:     playerIDCookieName(userName),
+					Value:    player.ID,
+					MaxAge:   cookieExpiry,
+					HttpOnly: true,
+					Path:     "/",
+				}
+				http.SetCookie(w, cookie)
 			}
 
-			cookie := &http.Cookie{
-				Name:     playerIDCookieName(userName),
-				Value:    player.ID,
-				MaxAge:   cookieExpiry,
-				HttpOnly: true,
-				Path:     "/",
-			}
-			http.SetCookie(w, cookie)
 			next.ServeHTTP(w, r)
 		})
 	}
diff --git a/server/subsonic/middlewares_test.go b/server/subsonic/middlewares_test.go
index 07b565aed..fe6eaa15a 100644
--- a/server/subsonic/middlewares_test.go
+++ b/server/subsonic/middlewares_test.go
@@ -2,6 +2,7 @@ package subsonic
 
 import (
 	"context"
+	"errors"
 	"net/http"
 	"net/http/httptest"
 	"strings"
@@ -156,6 +157,17 @@ var _ = Describe("Middlewares", func() {
 			Expect(cookieStr).To(ContainSubstring(playerIDCookieName("someone")))
 		})
 
+		It("does not add the cookie if there was an error", func() {
+			ctx := context.WithValue(r.Context(), "client", "error")
+			r = r.WithContext(ctx)
+
+			gp := getPlayer(mockedPlayers)(next)
+			gp.ServeHTTP(w, r)
+
+			cookieStr := w.Header().Get("Set-Cookie")
+			Expect(cookieStr).To(BeEmpty())
+		})
+
 		Context("PlayerId specified in Cookies", func() {
 			BeforeEach(func() {
 				cookie := &http.Cookie{
@@ -242,5 +254,8 @@ func (mp *mockPlayers) Get(ctx context.Context, playerId string) (*model.Player,
 }
 
 func (mp *mockPlayers) Register(ctx context.Context, id, client, typ, ip string) (*model.Player, *model.Transcoding, error) {
+	if client == "error" {
+		return nil, nil, errors.New(client)
+	}
 	return &model.Player{ID: id}, mp.transcoding, nil
 }