Thanks, Slawomir, Yeah, gorm connection pooling was the culprit. After I set up the max connection lifetime it started taking the change in FQDN without application restart.
We already have a setting for the skip-name-resolve value. On Fri, Jun 9, 2023 at 11:39 AM Slawomir Pryczek <slawek1...@gmail.com> wrote: > Probably > 1. You're using connection pool in gorm > 2. Gorm is using golang's connection pool > 3. The connection gets cached/reused while domain's IP changes (as the > address is same but ip changes and the change can't be easily detected) > > So the solution would probably be to do a lookup in a separated goroutine, > every X seconds using net.LookupIP (20 seconds should be good). Then > connecting directly to that IP instead of FQDN using gorm. > > BTW: If you're using mysql you should also add skip-name-resolve to server > config as it'd overload DNS server if you're making a lot of connections > and is totally unnecessary. > > środa, 7 czerwca 2023 o 20:42:17 UTC+2 Ian Lance Taylor napisał(a): > >> On Wed, Jun 7, 2023 at 5:13 AM Kishan Pandey <pandey....@gmail.com> >> wrote: >> > >> > My application is using gorm to connect to the database FQDN. If I am >> making changes to DNS record for the FQDN , the application needs to be >> restarted to take the DNS change. I think it is making the DNS query only >> at the application start time but not afterward. >> > >> > I would like to know how does golang manages the DNS changes. I looked >> at gorm issue and found one comment stating that gorm does not manage DNS >> cache its usage system default. >> >> The Go standard library doesn't cache DNS lookups. If you look up a >> name twice, it will generate two different DNS requests, or two >> different calls to getaddrinfo. That is, Go expects to be contacting >> a caching resolver. Of course, a Go program can do a DNS lookup and >> cache the results outside of the standard library. >> >> So while I don't know what problem you are encountering, it doesn't >> seem likely to be in the Go standard library. >> >> Ian >> > -- > You received this message because you are subscribed to a topic in the > Google Groups "golang-nuts" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/golang-nuts/1FxaM11WZ3M/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > golang-nuts+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/24fb2c2b-26cb-40b7-adde-d717db9bfcefn%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/24fb2c2b-26cb-40b7-adde-d717db9bfcefn%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CANSm8DdRNx%3DKK2pYg-5H8s%3D%2B7oauNMPyXpNknv570cryZ3CviA%40mail.gmail.com.