Comments (6)
We use iam rds tokens which expires
from pop.
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.
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.
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.
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.
This issue was closed because it has been stalled for 30+7 days with no activity.
from pop.
Related Issues (20)
- fix regex bug on the `WHERE col IN (?)`
- feature proposal: add support to oracle DB HOT 1
- bug: transaction panic recovery swallows panic message HOT 3
- feature: log transaction/connection ID to track SQL executions for a request
- feature: Read/Write routing to different endpoints HOT 2
- feature: improve performance if the element of the Value of *Model does not implement the AfterFindable interface. HOT 4
- bug: DB connection locks up under load calling DB.Create(), regression in 6.1.0 vs 6.0.8 HOT 8
- feature: parallelize association loading HOT 2
- process: update supported database versions
- bug: sqlite3 testing on Windows + go 1.17 failing sometimes HOT 3
- bug: incorrect error handling
- feature: upgrade jackc/pgx to v5 HOT 2
- feature: Dialect for Cassandra HOT 3
- feature: DB connection timeout HOT 2
- bug: "cannot parse UUID" on models.DB.Create HOT 1
- feature: context plumbing HOT 2
- bug: SQL connection leak when using EagerPreload HOT 4
- Slack Channel Not Working HOT 3
- is this project dead? HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pop.