MCPcopy Index your code
hub / github.com/coder/coder / refresh

Method refresh

tailnet/controllers.go:903–953  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

901}
902
903func (r *basicResumeTokenRefresher) refresh() {
904 if r.ctx.Err() != nil {
905 return // context done, no need to refresh
906 }
907 res, err := r.client.RefreshResumeToken(r.ctx, &proto.RefreshResumeTokenRequest{})
908 if xerrors.Is(err, context.Canceled) || xerrors.Is(err, context.DeadlineExceeded) {
909 // these can only come from being closed, no need to log
910 select {
911 case r.errCh <- nil:
912 default: // already have an error
913 }
914 return
915 }
916 if IsDRPCUnimplementedError(err) {
917 r.logger.Info(r.ctx, "resume token is not supported by the server")
918 select {
919 case r.errCh <- nil:
920 default: // already have an error
921 }
922 return
923 } else if err != nil {
924 r.logger.Error(r.ctx, "error refreshing coordinator resume token", slog.Error(err))
925 select {
926 case r.errCh <- err:
927 default: // already have an error
928 }
929 return
930 }
931 r.logger.Debug(r.ctx, "refreshed coordinator resume token",
932 slog.F("expires_at", res.GetExpiresAt()),
933 slog.F("refresh_in", res.GetRefreshIn()),
934 )
935 r.ctrl.Lock()
936 if r.ctrl.refresher == r { // don't overwrite if we're not the current refresher
937 r.ctrl.token = res
938 } else {
939 r.logger.Debug(context.Background(), "not writing token because we have a new client")
940 }
941 r.ctrl.Unlock()
942 dur := res.RefreshIn.AsDuration()
943 if dur <= 0 {
944 // A sensible delay to refresh again.
945 dur = 30 * time.Minute
946 }
947 r.Lock()
948 defer r.Unlock()
949 if r.closed {
950 return
951 }
952 r.timer.Reset(dur, "basicResumeTokenRefresher", "refresh")
953}
954
955type TunnelAllWorkspaceUpdatesController struct {
956 coordCtrl *TunnelSrcCoordController

Callers 1

Calls 11

IsDRPCUnimplementedErrorFunction · 0.85
ErrMethod · 0.80
GetExpiresAtMethod · 0.80
GetRefreshInMethod · 0.80
RefreshResumeTokenMethod · 0.65
ResetMethod · 0.65
IsMethod · 0.45
InfoMethod · 0.45
ErrorMethod · 0.45
LockMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected