diff --git a/backend/protondrive/session.go b/backend/protondrive/session.go index 330218ba1..4c94ffb1f 100644 --- a/backend/protondrive/session.go +++ b/backend/protondrive/session.go @@ -224,6 +224,10 @@ func (s *session) call(ctx context.Context, opts *rest.Opts, request, response a } } creds = s.current() + if creds.UID == "" { + // Signed out while the call was made. + return resp, s.signInNeeded(errNotSignedIn) + } return s.do(ctx, opts, request, response, &creds) } diff --git a/backend/protondrive/session_internal_test.go b/backend/protondrive/session_internal_test.go index ca258ea2d..3bdd0938d 100644 --- a/backend/protondrive/session_internal_test.go +++ b/backend/protondrive/session_internal_test.go @@ -526,3 +526,21 @@ func TestLogout(t *testing.T) { old.adoptWait = 0 assert.ErrorIs(t, authCall(context.Background(), old), errSessionExpired) } + +func TestCallDuringLogout(t *testing.T) { + t.Parallel() + ctx := context.Background() + srv := protontest.New(t) + s, _, _ := newTestSession(t, srv) + // The call is rejected only after the session has signed out. + srv.Inject(protontest.Fault{Method: "GET", Pattern: "/tests/auth", Times: 1, Status: http.StatusUnauthorized, Delay: 500 * time.Millisecond}) + errc := make(chan error, 1) + go func() { errc <- authCall(ctx, s) }() + require.Eventually(t, func() bool { return srv.Requests()["GET /tests/auth"] == 1 }, 5*time.Second, 5*time.Millisecond) + require.NoError(t, s.logout(ctx)) + + err := <-errc + assert.ErrorIs(t, err, errNotSignedIn) + assert.Equal(t, 1, srv.Requests()["GET /tests/auth"], "retried without credentials") + assert.Zero(t, srv.Requests()[refreshRoute]) +}