Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to connect to database (1-15) other than the default database 0 when using redis #15680

Closed
2 of 6 tasks
ziliwesley opened this issue Apr 30, 2021 · 3 comments · Fixed by #15698
Closed
2 of 6 tasks
Labels

Comments

@ziliwesley
Copy link

ziliwesley commented Apr 30, 2021

  • Gitea version (or commit ref): 1.14.1 (using offical Docker image)

  • Git version: Not Related

  • Operating system: Not Related

  • Database (use [x]):

    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:

    • Yes (provide example URL)
    • No

Description

I have been trying to setup a gitea deployment with kubernetes on my own machines with an external PostgreSQL as persistence store and an external Redis as cache store (session store as well).

Here is part of my /data/gitea/conf/app.ini

[session]
COOKIE_SECURE   = true
PROVIDER        = redis
# I have tried using this before, same outcome.
# PROVIDER_CONFIG: network=tcp,addr=some.host.addr:6379,password=some_password,db=14,pool_size=100,idle_timeout=180
PROVIDER_CONFIG = redis://:[email protected]:6379/14?pool_size=100&idle_timeout=100

After gitea sign in, session related key could be written to Redis successfully; the problem is, but only to the default database: db0; The database I chose (which is db14) got nothing.

Thoughts

After some reading of the source code, I found it maybe related to codes below

modules/nosql/redis.go

...
	case "db":
		uri.Path = "/" + items[1]
...

and modules/nosql/manager_redis.go

...
	case "redis":
		if uri.Host != "" {
			opts.Addrs = append(opts.Addrs, strings.Split(uri.Host, ",")...)
		}
		if uri.Path != "" {
			if db, err := strconv.Atoi(uri.Path); err == nil {
				opts.DB = db
			}
		}
		client.UniversalClient = redis.NewClient(opts.Simple())
...

I also wrote some simple codes to test it:

	ret, err := strconv.Atoi("/14")

	if err != nil {
		// Will panic: strconv.Atoi: parsing "/14": invalid syntax
		panic(err)
	}

	log.Printf("parsed: %v", ret)
@wULLSnpAXbWZGYDYyhWTKKspEQoaYxXyhoisqHf
Copy link
Contributor

this string works fine for me, although it's the db0..
network=tcp,addr=:6379,password=ultralongandrandom,db=0,pool_size=100,idle_timeout=180

that's what's not working as well, right?

@ziliwesley
Copy link
Author

this string works fine for me, although it's the db0..
network=tcp,addr=:6379,password=ultralongandrandom,db=0,pool_size=100,idle_timeout=180

that's what's not working as well, right?

Yes. It's working fine to connect the db0 using both methods.

@zeripath
Copy link
Contributor

zeripath commented May 1, 2021

Yup looks like you've spotted a bug! Should be fixed by #15698

@go-gitea go-gitea locked and limited conversation to collaborators Jun 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants