Error 500 on first OAuth login attempt after restart #2372

Closed
opened 2025-11-02 04:34:02 -06:00 by GiteaMirror · 14 comments
Owner

Originally created by @coolaj86 on GitHub (Oct 3, 2018).

  • Gitea version (or commit ref): v1.9-dev, v1.5.1 (and earlier)
  • Git version:
  • Operating system: Linux
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • Not relevant
  • Log gist:

Description

Every time I first start gitea, the very first login attempt with oauth will result in a 500 error.

It doesn't happen again even if I clear the browser application cache.

It doesn't happen again even if I revoke the oauth app and go through the oauth flow again.

I believe I can narrow it down more, but I've experienced it in production several times after upgrading and restarting. I'll have to set up a dev environment to test it and get the logs (in prod the HTTP GETs just blow everything else away pretty quickly).

Originally created by @coolaj86 on GitHub (Oct 3, 2018). - Gitea version (or commit ref): v1.9-dev, v1.5.1 (and earlier) - Git version: - Operating system: Linux - Database (use `[x]`): - [ ] PostgreSQL - [ ] MySQL - [ ] MSSQL - [x] SQLite - Can you reproduce the bug at https://try.gitea.io: - [ ] Yes (provide example URL) - [ ] No - [x] Not relevant - Log gist: ## Description Every time I first start gitea, the very first login attempt with oauth will result in a 500 error. It doesn't happen again even if I clear the browser application cache. It doesn't happen again even if I revoke the oauth app and go through the oauth flow again. I believe I can narrow it down more, but I've experienced it in production several times after upgrading and restarting. I'll have to set up a dev environment to test it and get the logs (in prod the HTTP GETs just blow everything else away pretty quickly).
GiteaMirror added the issue/confirmedtype/bugissue/needs-feedback labels 2025-11-02 04:34:02 -06:00
Author
Owner

@coolaj86 commented on GitHub (Oct 3, 2018):

Although I’ve seen this multiple times, I can’t find the right conditions to reproduce it and it’s not as simple as just restarting.

I’ll close for now and reopen later if I can reproduce.

@coolaj86 commented on GitHub (Oct 3, 2018): Although I’ve seen this multiple times, I can’t find the right conditions to reproduce it and it’s not as simple as just restarting. I’ll close for now and reopen later if I can reproduce.
Author
Owner

@coolaj86 commented on GitHub (Apr 14, 2019):

This is still plaguing me on 1.9-dev. It looks like it's related to this error in the logs:

handleOAuth2SignIn() [E] UserSignIn: could not find a matching session for this request
@coolaj86 commented on GitHub (Apr 14, 2019): This is still plaguing me on 1.9-dev. It looks like it's related to this error in the logs: ``` handleOAuth2SignIn() [E] UserSignIn: could not find a matching session for this request ```
Author
Owner

@lunny commented on GitHub (Apr 14, 2019):

This should be resolved by https://github.com/go-gitea/gitea/pull/6467

@lunny commented on GitHub (Apr 14, 2019): This should be resolved by https://github.com/go-gitea/gitea/pull/6467
Author
Owner

@coolaj86 commented on GitHub (Apr 16, 2019):

It doesn't seem to be.

@coolaj86 commented on GitHub (Apr 16, 2019): It doesn't seem to be.
Author
Owner

@coolaj86 commented on GitHub (Apr 18, 2019):

See also: https://github.com/go-gitea/gitea/issues/3837#issuecomment-483820520

@coolaj86 commented on GitHub (Apr 18, 2019): See also: https://github.com/go-gitea/gitea/issues/3837#issuecomment-483820520
Author
Owner

@stale[bot] commented on GitHub (Jun 17, 2019):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 weeks. Thank you for your contributions.

@stale[bot] commented on GitHub (Jun 17, 2019): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 weeks. Thank you for your contributions.
Author
Owner

@benchti commented on GitHub (Aug 22, 2019):

Just to notify I just had the same error
Gitea Version: 1.9.1 / Go1.11.5

@benchti commented on GitHub (Aug 22, 2019): Just to notify I just had the same error Gitea Version: 1.9.1 / Go1.11.5
Author
Owner

@camlafit commented on GitHub (Aug 27, 2019):

Hello

For information, I manage server related by @benchti , we can do any test required. Note it's now updated to 1.9.2

@camlafit commented on GitHub (Aug 27, 2019): Hello For information, I manage server related by @benchti , we can do any test required. Note it's now updated to 1.9.2
Author
Owner

@noerw commented on GitHub (Nov 13, 2020):

I had a similar issue still on v1.13.0-rc1 with Nextcloud OAuth2 provider at the first login with a new account.
I'll try to figure out the general conditions..

@noerw commented on GitHub (Nov 13, 2020): I had a similar issue still on v1.13.0-rc1 with Nextcloud OAuth2 provider at the first login with a new account. I'll try to figure out the general conditions..
Author
Owner

@lunny commented on GitHub (Mar 24, 2021):

2021/03/24 09:36:18 ...uters/routes/base.go:36:1() [I] Started GET /user/oauth2/github/callback?code=xxxxxxxxx&state=xxxxxxxxxxxxxx for 35.221.190.49:0
2021/03/24 09:36:18 ...m.io/xorm/core/db.go:286:afterProcess() [I] [SQL] SELECT `id`, `type`, `name`, `is_actived`, `is_sync_enabled`, `cfg`, `created_unix`, `updated_unix` FROM `login_source` WHERE (name = ? and type = ? and is_actived = ?) LIMIT 1 [github 6 true] - 736.295µs
2021/03/24 09:36:18 ...m.io/xorm/core/db.go:286:afterProcess() [I] [SQL] SELECT `id`, `data`, `created_unix`, `updated_unix`, `expires_unix` FROM `oauth2_session` WHERE (id = ? AND expires_unix >= ?) LIMIT 1 [xxxxxxxxx xxxxxxxx] - 511.573µs
2021/03/24 09:36:18 routers/user/auth.go:617:handleOAuth2SignIn() [E] UserSignIn: could not find a matching session for this request
	/source/routers/user/auth.go:617 (0x1fa4605)
	/source/routers/user/auth.go:612 (0x1fa355e)
	/source/modules/web/route.go:53 (0x1f7c482)
	/usr/local/go/src/net/http/server.go:2069 (0x7bd0a3)
	/source/vendor/github.com/go-chi/chi/mux.go:436 (0x1b355aa)
	/usr/local/go/src/net/http/server.go:2069 (0x7bd0a3)
	/source/modules/web/route.go:91 (0x1f7ca16)
	/usr/local/go/src/net/http/server.go:2069 (0x7bd0a3)
	/source/modules/web/route.go:91 (0x1f7ca16)
	/usr/local/go/src/net/http/server.go:2069 (0x7bd0a3)
	/source/modules/web/route.go:91 (0x1f7ca16)
	/usr/local/go/src/net/http/server.go:2069 (0x7bd0a3)
	/source/vendor/github.com/go-chi/chi/middleware/get_head.go:37 (0x21ad441)
	/usr/local/go/src/net/http/server.go:2069 (0x7bd0a3)
	/source/modules/context/context.go:704 (0x1b517e1)
	/usr/local/go/src/net/http/server.go:2069 (0x7bd0a3)
	/source/routers/routes/base.go:94 (0x21b4a01)
	/usr/local/go/src/net/http/server.go:2069 (0x7bd0a3)
	/source/routers/routes/base.go:94 (0x21b4a01)
	/usr/local/go/src/net/http/server.go:2069 (0x7bd0a3)
	/source/modules/public/public.go:85 (0x13f38e7)
	/usr/local/go/src/net/http/server.go:2069 (0x7bd0a3)
	/source/modules/public/public.go:85 (0x13f38e7)
	/usr/local/go/src/net/http/server.go:2069 (0x7bd0a3)
	/source/routers/routes/base.go:199 (0x21b65f0)
	/usr/local/go/src/net/http/server.go:2069 (0x7bd0a3)
	/source/vendor/gitea.com/go-chi/session/session.go:256 (0x154508e)
	/usr/local/go/src/net/http/server.go:2069 (0x7bd0a3)
	/source/vendor/github.com/go-chi/chi/mux.go:70 (0x1b3310a)
	/source/vendor/github.com/go-chi/chi/mux.go:311 (0x1b394fb)
	/usr/local/go/src/net/http/server.go:2069 (0x7bd0a3)
	/source/vendor/github.com/go-chi/chi/mux.go:436 (0x1b355aa)
	/usr/local/go/src/net/http/server.go:2069 (0x7bd0a3)
	/source/routers/routes/web.go:110 (0x21b7a3d)
	/usr/local/go/src/net/http/server.go:2069 (0x7bd0a3)
	/source/routers/routes/base.go:38 (0x21b367b)
	/usr/local/go/src/net/http/server.go:2069 (0x7bd0a3)
	/source/vendor/github.com/go-chi/chi/middleware/strip.go:30 (0x21add47)
	/usr/local/go/src/net/http/server.go:2069 (0x7bd0a3)
	/source/vendor/github.com/chi-middleware/proxy/middleware.go:37 (0x21a93ae)
	/usr/local/go/src/net/http/server.go:2069 (0x7bd0a3)
	/source/routers/routes/web.go:66 (0x21b757c)
	/usr/local/go/src/net/http/server.go:2069 (0x7bd0a3)
	/source/vendor/github.com/go-chi/chi/mux.go:87 (0x1b32e90)
	/source/modules/web/route.go:267 (0x1f7b9d3)
	/source/vendor/github.com/gorilla/context/context.go:141 (0x11b2e53)
	/usr/local/go/src/net/http/server.go:2069 (0x7bd0a3)
	/usr/local/go/src/net/http/server.go:2887 (0x7c0662)
	/usr/local/go/src/net/http/server.go:1952 (0x7bbb8c)
	/usr/local/go/src/runtime/asm_amd64.s:1371 (0x47a460)
	

2021/03/24 09:36:18 ...uters/routes/base.go:45:1() [I] Completed GET /user/oauth2/github/callback?code=xxxxxxx&state=xxxxxxxx 500 Internal Server Error in 3.592015ms
@lunny commented on GitHub (Mar 24, 2021): ``` 2021/03/24 09:36:18 ...uters/routes/base.go:36:1() [I] Started GET /user/oauth2/github/callback?code=xxxxxxxxx&state=xxxxxxxxxxxxxx for 35.221.190.49:0 2021/03/24 09:36:18 ...m.io/xorm/core/db.go:286:afterProcess() [I] [SQL] SELECT `id`, `type`, `name`, `is_actived`, `is_sync_enabled`, `cfg`, `created_unix`, `updated_unix` FROM `login_source` WHERE (name = ? and type = ? and is_actived = ?) LIMIT 1 [github 6 true] - 736.295µs 2021/03/24 09:36:18 ...m.io/xorm/core/db.go:286:afterProcess() [I] [SQL] SELECT `id`, `data`, `created_unix`, `updated_unix`, `expires_unix` FROM `oauth2_session` WHERE (id = ? AND expires_unix >= ?) LIMIT 1 [xxxxxxxxx xxxxxxxx] - 511.573µs 2021/03/24 09:36:18 routers/user/auth.go:617:handleOAuth2SignIn() [E] UserSignIn: could not find a matching session for this request /source/routers/user/auth.go:617 (0x1fa4605) /source/routers/user/auth.go:612 (0x1fa355e) /source/modules/web/route.go:53 (0x1f7c482) /usr/local/go/src/net/http/server.go:2069 (0x7bd0a3) /source/vendor/github.com/go-chi/chi/mux.go:436 (0x1b355aa) /usr/local/go/src/net/http/server.go:2069 (0x7bd0a3) /source/modules/web/route.go:91 (0x1f7ca16) /usr/local/go/src/net/http/server.go:2069 (0x7bd0a3) /source/modules/web/route.go:91 (0x1f7ca16) /usr/local/go/src/net/http/server.go:2069 (0x7bd0a3) /source/modules/web/route.go:91 (0x1f7ca16) /usr/local/go/src/net/http/server.go:2069 (0x7bd0a3) /source/vendor/github.com/go-chi/chi/middleware/get_head.go:37 (0x21ad441) /usr/local/go/src/net/http/server.go:2069 (0x7bd0a3) /source/modules/context/context.go:704 (0x1b517e1) /usr/local/go/src/net/http/server.go:2069 (0x7bd0a3) /source/routers/routes/base.go:94 (0x21b4a01) /usr/local/go/src/net/http/server.go:2069 (0x7bd0a3) /source/routers/routes/base.go:94 (0x21b4a01) /usr/local/go/src/net/http/server.go:2069 (0x7bd0a3) /source/modules/public/public.go:85 (0x13f38e7) /usr/local/go/src/net/http/server.go:2069 (0x7bd0a3) /source/modules/public/public.go:85 (0x13f38e7) /usr/local/go/src/net/http/server.go:2069 (0x7bd0a3) /source/routers/routes/base.go:199 (0x21b65f0) /usr/local/go/src/net/http/server.go:2069 (0x7bd0a3) /source/vendor/gitea.com/go-chi/session/session.go:256 (0x154508e) /usr/local/go/src/net/http/server.go:2069 (0x7bd0a3) /source/vendor/github.com/go-chi/chi/mux.go:70 (0x1b3310a) /source/vendor/github.com/go-chi/chi/mux.go:311 (0x1b394fb) /usr/local/go/src/net/http/server.go:2069 (0x7bd0a3) /source/vendor/github.com/go-chi/chi/mux.go:436 (0x1b355aa) /usr/local/go/src/net/http/server.go:2069 (0x7bd0a3) /source/routers/routes/web.go:110 (0x21b7a3d) /usr/local/go/src/net/http/server.go:2069 (0x7bd0a3) /source/routers/routes/base.go:38 (0x21b367b) /usr/local/go/src/net/http/server.go:2069 (0x7bd0a3) /source/vendor/github.com/go-chi/chi/middleware/strip.go:30 (0x21add47) /usr/local/go/src/net/http/server.go:2069 (0x7bd0a3) /source/vendor/github.com/chi-middleware/proxy/middleware.go:37 (0x21a93ae) /usr/local/go/src/net/http/server.go:2069 (0x7bd0a3) /source/routers/routes/web.go:66 (0x21b757c) /usr/local/go/src/net/http/server.go:2069 (0x7bd0a3) /source/vendor/github.com/go-chi/chi/mux.go:87 (0x1b32e90) /source/modules/web/route.go:267 (0x1f7b9d3) /source/vendor/github.com/gorilla/context/context.go:141 (0x11b2e53) /usr/local/go/src/net/http/server.go:2069 (0x7bd0a3) /usr/local/go/src/net/http/server.go:2887 (0x7c0662) /usr/local/go/src/net/http/server.go:1952 (0x7bbb8c) /usr/local/go/src/runtime/asm_amd64.s:1371 (0x47a460) 2021/03/24 09:36:18 ...uters/routes/base.go:45:1() [I] Completed GET /user/oauth2/github/callback?code=xxxxxxx&state=xxxxxxxx 500 Internal Server Error in 3.592015ms ```
Author
Owner

@senthilrch commented on GitHub (Jun 22, 2021):

I have exactly the same issue using Gitea v1.13.7:-

2021/06/22 06:30:08 routers/user/auth.go:612:handleOAuth2SignIn() [E] UserSignIn: could not find a matching session for this request
@senthilrch commented on GitHub (Jun 22, 2021): I have _exactly_ the same issue using Gitea v1.13.7:- ``` 2021/06/22 06:30:08 routers/user/auth.go:612:handleOAuth2SignIn() [E] UserSignIn: could not find a matching session for this request ```
Author
Owner

@zeripath commented on GitHub (Jun 22, 2021):

I suspect it's some issue to do with the loginsources not registering their providers with gothic (or not actually completely registered by the time that it comes to login.)

I think however that the use of gothic here is probably incorrect and we should just use goth or just the providers directly ourselves.

I guess I will have a look in #16199 or after that is merged.

@zeripath commented on GitHub (Jun 22, 2021): I suspect it's some issue to do with the loginsources not registering their providers with gothic (or not actually completely registered by the time that it comes to login.) I think however that the use of gothic here is probably incorrect and we should just use goth or just the providers directly ourselves. I guess I will have a look in #16199 or after that is merged.
Author
Owner

@jacksgt commented on GitHub (Feb 13, 2022):

Hey,
I'm seeing this issue also on Gitea 1.15.11. It's exactly the same as described above, so I won't repeat all the details.
Is there any way I can help debug this issue?
(I'm familiar with Go and it's debugging tools if that helps, however don't have any knowledge about the Gitea application so I would need some pointers).

@jacksgt commented on GitHub (Feb 13, 2022): Hey, I'm seeing this issue also on Gitea 1.15.11. It's exactly the same as described above, so I won't repeat all the details. Is there any way I can help debug this issue? (I'm familiar with Go and it's debugging tools if that helps, however don't have any knowledge about the Gitea application so I would need some pointers).
Author
Owner

@wxiaoguang commented on GitHub (Sep 12, 2023):

For this error: [E] UserSignIn: could not find a matching session for this request

Two possibilities:

  1. ROOT_URL doesn't match
  2. #27033

I think this issue could be closed

@wxiaoguang commented on GitHub (Sep 12, 2023): For this error: [E] UserSignIn: could not find a matching session for this request Two possibilities: 1. ROOT_URL doesn't match 2. #27033 I think this issue could be closed
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#2372