From 8dacac60ea00d8549ad26efe6733495f10375f2d Mon Sep 17 00:00:00 2001 From: albertony <12441419+albertony@users.noreply.github.com> Date: Thu, 9 Oct 2025 14:54:06 +0200 Subject: [PATCH] jottacloud: improved token refresh handling The oauthutil.Renew was initialized early in NewFs, before the first request to the service where a token is needed. When token is already expired at the time NewFs is called, the Renew operation would be triggered immediately, only to abort before actually performing a token refresh, for reason described in debug message: Token expired but no uploads in progress - doing nothing Then later in NewFs, a request to the customer endpoint was made, and since it requires a valid token it would perform a token refresh after all. This was not a big problem, but a bit unnecessary, and the debug log messages made it confusing to understand what rclone was actually doing regarding token refreshing. If, from debugger, we were forcing the Renew operation to perform actual token refresh, even if no uploads in process, then it would fail because it actually needs the username which is retrieved from the customer endpoint jottacloud root '': Token refresh failed: read metadata failed: error 400: org.springframework.security.core.userdetails.UsernameNotFoundException: Username not found in url! (Bad Request) Don't think this can happen in any real situations, but better to make sure it never can. --- backend/jottacloud/jottacloud.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/backend/jottacloud/jottacloud.go b/backend/jottacloud/jottacloud.go index dd3983047..235856700 100644 --- a/backend/jottacloud/jottacloud.go +++ b/backend/jottacloud/jottacloud.go @@ -993,6 +993,13 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, e f.features.ListR = nil } + cust, err := getCustomerInfo(ctx, f.apiSrv) + if err != nil { + return nil, err + } + f.user = cust.Username + f.setEndpoints() + // Renew the token in the background f.tokenRenewer = oauthutil.NewRenew(f.String(), ts, func() error { _, err := f.readMetaDataForPath(ctx, "") @@ -1002,13 +1009,6 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, e return err }) - cust, err := getCustomerInfo(ctx, f.apiSrv) - if err != nil { - return nil, err - } - f.user = cust.Username - f.setEndpoints() - if root != "" && !rootIsDir { // Check to see if the root actually an existing file remote := path.Base(root)