Giter VIP home page Giter VIP logo

Comments (6)

chakramarla avatar chakramarla commented on July 21, 2024

We use iam rds tokens which expires

from pop.

sio4 avatar sio4 commented on July 21, 2024

Is there a way to reset connection configs regularly? If not I don't see any workaround for this issue, we need some callback before newconnection/openconnection call where user can reset db creds/configs.

The connection information is just configured when it is initialized and Pop does not support periodic reconfiguration.

Anyway, it is interesting to me, and I would like to ask you for the details of how you configured it initially and what could be the best approach for your condition. Could you please explain more with some examples of your configuration?

from pop.

chakramarla avatar chakramarla commented on July 21, 2024

sio4, thanks for response.
We use AWS IAM rds tokens for db authentication which expire after 15 mins.
Here is the AWS sample code for db connection using IAM authentication
https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/UsingWithRDS.IAMDBAuth.Connecting.Go.html

Here is my code snippet:

        cfg, err := config.LoadDefaultConfig(context.TODO())
	if err != nil {		
		panic("configuration error: " + err.Error())
	}
	env := envy.Get("GO_ENV", "development")
	authenticationToken, err := auth.BuildAuthToken(context.TODO(), dbEndpoint, region, dbUser, cfg.Credentials)
	if err != nil {
		panic("failed to create authentication token: " + err.Error())		
	}
	dsn := fmt.Sprintf("%s:%s@tcp(%s)/%s?allowCleartextPasswords=true&parseTime=true&multiStatements=true&tls=true",
		dbUser, authenticationToken, dbEndpoint, dbName,
	)
	var connection *pop.Connection
	DB, err = pop.NewConnection(&pop.ConnectionDetails{
		Dialect: "mysql",
		URL:     dsn,
	})
       if err != nil {
           panic("failed to create db connection error: " + err)
       }
      if err = DB.Open(); err != nil {
          panic("failed to open db connection error: " + err)
      }

The db connection works even after 15 mins, it fails only when it tries to reopen connection after a db disconnected.
Appreciate your help.

from pop.

sio4 avatar sio4 commented on July 21, 2024

Oh, I see. This is interesting but I think this issue should be covered by the application level at least for now.

What I understand is that the issue is not about a single connection from the connection pool but about when the application lost all the connections and it needs to reconnect to the database engine. (e.g. the database engine restarted or there was a network connectivity issue and it was recovered) Is my understanding correct?

Let's see the code you shared. (I edited your comment to make it easy to read the code part)

It seems like you use Pop directly in your app without Buffalo, and you use pop.NewConnection() to get DB instance. When the call returns a DB instance, the dsn built with auth.BuildAithToken() and provided to the NewConnection() is already fixed in the instance at that moment (with credential) so all following connections to the database engine will use the connection information. The information never be changed because the application never calls the routine again.

It could be solved at the driver level if the driver is aware of AWS's token authentication method and the token updating routine is implemented in the driver's connector code. (just a possibility) However, this is driver-specific and Pop does not directly handle the actual connection.

As a workaround, I think you could make a connection refresher function with the code snippet and call it when you detected the connection failure to the database engine in your app.

from pop.

github-actions avatar github-actions commented on July 21, 2024

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment. Otherwise, this will be closed in 7 days.

from pop.

github-actions avatar github-actions commented on July 21, 2024

This issue was closed because it has been stalled for 30+7 days with no activity.

from pop.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.