Skip to content

Commit

Permalink
fix(oracle): disabling global hidden internal timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienaury committed Jun 4, 2024
1 parent d755bee commit dae9a49
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 19 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ Types of changes
- `Fixed` for any bug fixes.
- `Security` in case of vulnerabilities.

## [3.0.1]

- `Fixed` hidden global internal timeout of 240s with Oracle driver is now disabled by default

## [3.0.0]

- `Changed` table or column names were not correctly matched in terms of case sensitivity (lowercase or uppercase) in table.yaml
Expand Down
11 changes: 3 additions & 8 deletions internal/app/query/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package query
import (
"fmt"
"os"
"time"

"github.com/cgi-fr/lino/internal/app/urlbuilder"
infra "github.com/cgi-fr/lino/internal/infra/query"
Expand All @@ -28,31 +27,27 @@ func Inject(

// NewCommand implements the cli analyse command
func NewCommand(fullName string, err *os.File, out *os.File, in *os.File) *cobra.Command {
var maxLifeTime time.Duration

cmd := &cobra.Command{
Use: "query",
Short: "Execute direct query",
Example: fmt.Sprintf(" %[1]s", fullName),
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
if er := execute(cmd, args[0], args[1], maxLifeTime); er != nil {
if er := execute(cmd, args[0], args[1]); er != nil {
fmt.Fprintln(err, er.Error())
os.Exit(1)
}
},
}

cmd.Flags().DurationVarP(&maxLifeTime, "timeout", "t", 4*time.Minute, "sets the maximum amount of time a connection may be reused")

cmd.SetOut(out)
cmd.SetErr(err)
cmd.SetIn(in)

return cmd
}

func execute(cmd *cobra.Command, dataconnectorName string, querystr string, maxLifeTime time.Duration) error {
func execute(cmd *cobra.Command, dataconnectorName string, querystr string) error {
alias, e1 := dataconnector.Get(dataconnectorStorage, dataconnectorName)
if e1 != nil {
return e1
Expand All @@ -69,7 +64,7 @@ func execute(cmd *cobra.Command, dataconnectorName string, querystr string, maxL
return fmt.Errorf("no extractor found for database type")
}

driver := query.NewDriver(dataSourceFactory.New(u.URL.String(), maxLifeTime), infra.NewJSONWriter(cmd.OutOrStdout()))
driver := query.NewDriver(dataSourceFactory.New(u.URL.String()), infra.NewJSONWriter(cmd.OutOrStdout()))

if err := driver.Open(); err != nil {
return fmt.Errorf("%w", err)
Expand Down
3 changes: 3 additions & 0 deletions internal/app/urlbuilder/urlbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ func getOptions(u *dburl.URL) map[string]string {

options := make(map[string]string, len(values))

// fix: we want the global timeout to be disabled, like it is for every other drivers
options["TIMEOUT"] = "0"

for key, vals := range values {
if len(vals) > 0 {
options[key] = vals[len(vals)-1]
Expand Down
16 changes: 5 additions & 11 deletions internal/infra/query/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package query

import (
"fmt"
"time"

"github.com/cgi-fr/lino/pkg/query"
"github.com/jmoiron/sqlx"
Expand Down Expand Up @@ -55,9 +54,8 @@ func (dr *DataReader) Error() error {
}

type DataSource struct {
url string
dbx *sqlx.DB
maxLifeTime time.Duration
url string
dbx *sqlx.DB
}

func (ds *DataSource) Open() error {
Expand All @@ -73,9 +71,6 @@ func (ds *DataSource) Open() error {

ds.dbx = sqlx.NewDb(db, u.UnaliasedDriver)

ds.dbx.SetConnMaxLifetime(ds.maxLifeTime)
ds.dbx.SetConnMaxIdleTime(ds.maxLifeTime)

err = ds.dbx.Ping()
if err != nil {
return fmt.Errorf("%w", err)
Expand Down Expand Up @@ -105,10 +100,9 @@ func (ds *DataSource) Query(query string) (query.DataReader, error) {

type DataSourceFactory struct{}

func (dsf DataSourceFactory) New(url string, maxLifeTime time.Duration) query.DataSource {
func (dsf DataSourceFactory) New(url string) query.DataSource {
return &DataSource{
url: url,
dbx: nil,
maxLifeTime: maxLifeTime,
url: url,
dbx: nil,
}
}

0 comments on commit dae9a49

Please sign in to comment.