session-extend: preempt previous WaitExtendAuthSession on new wait

When the tray "Extend now" notification action and the about-to-expire
dialog both start a flow for the same deadline, the daemon was running
two independent IdP polls and the older one surfaced an InvalidArgument
toast as soon as the second RequestExtend overwrote the pending flow.

Follow the WaitSSOLogin pattern: at the top of WaitExtendAuthSession
cancel the previous wait (the SetWaitCancel/CancelWait pair on
PendingFlow already existed but was unused), then register the new
wait's cancel. Preempted callers exit with codes.Canceled; the
authsession service translates that into ExtendResult{Preempted: true}
so the tray and the React dialog can stay silent on the losing flow
instead of showing a false-failure toast / error dialog.
This commit is contained in:
Zoltán Papp
2026-05-28 19:17:46 +02:00
parent c1db8ab0ab
commit e94a4cbce5
4 changed files with 45 additions and 5 deletions

View File

@@ -6,6 +6,9 @@ import (
"context"
"time"
"google.golang.org/grpc/codes"
gstatus "google.golang.org/grpc/status"
"github.com/netbirdio/netbird/client/proto"
)
@@ -34,9 +37,12 @@ type ExtendWaitParams struct {
// ExtendResult carries the refreshed deadline. ExpiresAt is nil when the
// management server reported the peer is not eligible for session
// extension.
// extension. Preempted is true when a newer WaitExtend (e.g. started from
// another UI surface for the same deadline) took over the IdP poll —
// callers should treat the call as a no-op rather than a failure.
type ExtendResult struct {
ExpiresAt *time.Time `json:"sessionExpiresAt,omitempty"`
Preempted bool `json:"preempted,omitempty"`
}
// DaemonConn yields a lazy daemon gRPC client. Mirrors services.DaemonConn
@@ -101,6 +107,9 @@ func (s *Session) WaitExtend(ctx context.Context, p ExtendWaitParams) (ExtendRes
UserCode: p.UserCode,
})
if err != nil {
if st, ok := gstatus.FromError(err); ok && st.Code() == codes.Canceled {
return ExtendResult{Preempted: true}, nil
}
return ExtendResult{}, err
}