R
Railway14mo ago
Kronborg

Go api with gofiber using session storage with redis

Hello i start to get this Error: /app/api/database/connect.go:28 +0x15b main.main() /app/main.go:73 +0x4a panic: dial tcp: lookup containers-us-west-181.railway.app: i/o timeout somtimes is stop after 1 min somtimes is take 5 min here is the conntion: func InitRedis() (*redis.Storage, error) { port, err := strconv.Atoi(os.Getenv("REDISPORT")) if err != nil { port = 6379 } storage := redis.New(redis.Config{ Host: os.Getenv("REDISHOST"), Port: port, Username: os.Getenv("REDISUSER"), Password: os.Getenv("REDISPASSWORD"), Database: 0, Reset: false, TLSConfig: nil, PoolSize: 10 * runtime.GOMAXPROCS(0), }) return storage, nil } i have add the log file
16 Replies
Percy
Percy14mo ago
Project ID: ac27f0b8-f4c4-478f-9516-441b9a3c376e
Kronborg
KronborgOP14mo ago
ac27f0b8-f4c4-478f-9516-441b9a3c376e
Brody
Brody14mo ago
add a time.Sleep(3 * time.Second) right before the redis.New line
Kronborg
KronborgOP14mo ago
okay i will try that on the next deploy
Brody
Brody14mo ago
I also would really not recommend trying to dynamically compute the pool size, or anything that relies on determining the cpu count while on Railway because go will detect the 32 cores of the host machine and throw your code out of wack for lack of a better word
Kronborg
KronborgOP14mo ago
okay is they a good number to set it at?
Brody
Brody14mo ago
you're on hobby, so you have 8 vcpus, set the pool variable at a static 80
Kronborg
KronborgOP14mo ago
this is the default PoolSize: 10 * runtime.GOMAXPROCS(0),
Brody
Brody14mo ago
by using that go max procs function and setting it to zero, you are telling go to use 0 cpus, this would have unintended consequences down the line
Kronborg
KronborgOP14mo ago
okay i just show this var ConfigDefault = Config{ Host: "127.0.0.1", Port: 6379, Username: "", Password: "", URL: "", Database: 0, Reset: false, TLSConfig: nil, PoolSize: 10 * runtime.GOMAXPROCS(0), Addrs: []string{}, MasterName: "", ClientName: "", SentinelUsername: "", SentinelPassword: "", }
Brody
Brody14mo ago
what redis package are you using?
Kronborg
KronborgOP14mo ago
github.com/gofiber/storage/redis/v3
Brody
Brody14mo ago
set it to 80
Kronborg
KronborgOP14mo ago
okay thx i will do that just to be clear you mean like PoolSize: 80,
Brody
Brody14mo ago
yes
Kronborg
KronborgOP14mo ago
Thx that did it
Want results from more Discord servers?
Add your server