woodpecker-ci / woodpecker

Woodpecker is a simple, yet powerful CI/CD engine with great extensibility.
https://woodpecker-ci.org
Apache License 2.0
4.23k stars 367 forks source link

Failed to load branches on public repo #4244

Open zc-devs opened 5 days ago

zc-devs commented 5 days ago

Component

server, web-ui

Describe the bug

Trying to open Branches tab on public repo, I get infinite loading spinner and error : failed to load branches: user does not exist [uid: 0, name: ]

Steps to reproduce

  1. Install Woodpecker and Gitea
  2. Login, add some public repo
  3. Leave it for 1 hour without activity
  4. Under anonymous user open the repo Screenshot 2024-10-22 1
  5. Try to open Branches tab Screenshot 2024-10-22 2 In browser console see error
    
    GET
    https://domain.tld/api/repos/2/branches?page=1
    [HTTP/2 500  255ms]

Error: : failed to load branches: user does not exist [uid: 0, name: ] _request https://domain.tld/assets/index-CaKTCYMy.js:44 _get https://domain.tld/assets/index-CaKTCYMy.js:44 getRepoBranches https://domain.tld/assets/index-CaKTCYMy.js:44

6. In Server log see

{"level":"trace","time":"2024-10-22T16:10:12Z","caller":"/woodpecker/src/github.com/woodpecker-ci/woodpecker/server/router/router.go:43","message":"[GET] /api/repos/2/branches?page=1"} {"level":"debug","time":"2024-10-22T16:10:12Z","caller":"/woodpecker/src/github.com/woodpecker-ci/woodpecker/server/router/middleware/session/repo.go:160","message":"guest granted &{UserID:0 RepoID:0 Repo: Pull:true Push:false Admin:false Synced:0 Created:0 Updated:0} to wp/test"} {"level":"error","error":"user does not exist [uid: 0, name: ]","time":"2024-10-22T16:10:12Z","caller":"/woodpecker/src/github.com/woodpecker-ci/woodpecker/server/api/repo.go:363","message":"failed to load branches"} {"level":"debug","ip":"1.2.3.4","latency":82.330564,"method":"GET","path":"/api/repos/2/branches","status":500,"time":"2024-10-22T16:10:12Z","user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:131.0) Gecko/20100101 Firefox/131.0","time":"2024-10-22T16:10:12Z","caller":"/woodpecker/src/github.com/woodpecker-ci/woodpecker/server/router/middleware/logger.go:59"}

7. In Gitea log see

2024/10/22 16:12:56 ...eb/routing/logger.go:102:func1() [I] router: completed GET /api/v1/version for [4.3.2.1]:0, 401 Unauthorized in 1.1ms @ v1/api.go:748(v1.Routes.apiAuth)


### Expected behavior

1. Branches list loads just fine
2. Or there is no Branches tab at all

### System Info

```shell
Woodpecker `next-9dd796ad65`, Gitea `1.22.3`, Potgres 16

Additional context

The same on 2.7.1, but there are two An unknown error occurred in UI without details (in server logs the same error as on next).

Validations

qwerty287 commented 3 days ago

Works here: https://ci.woodpecker-ci.org/repos/3780/branches

Can you try to find the cause?

zc-devs commented 3 days ago

I think it's about user token.

I have not been logged in for a while, got errors. My user had tokens:

// users.token
{
  "gnt": 1,
  "tt": 0,
  "exp": 1729508761, // Monday, October 21, 2024 11:06:01 AM
  "iat": 1729505161 // Monday, October 21, 2024 10:06:01 AM
}
// users.secret
{
  "gnt": 1,
  "tt": 1,
  "exp": 1732133161, // Wednesday, November 20, 2024 8:06:01 PM
  "iat": 1729505161 // Monday, October 21, 2024 10:06:01 AM
}

After logging in and logging out, Branches list works under anonymous user too and I got updated users table:

// users.token
{
  "gnt": 1,
  "tt": 0,
  "exp": 1729765645, // Thursday, October 24, 2024 10:27:25 AM
  "iat": 1729762045 // Thursday, October 24, 2024 9:27:25 AM
}
// users.secret
{
  "gnt": 1,
  "tt": 1,
  "exp": 1732390045, // Saturday, November 23, 2024 7:27:25 PM
  "iat": 1729762045 // Thursday, October 24, 2024 9:27:25 AM
}

So yes, after 1 hour since login/logout I have the same error. I've updated the issue.