Skip to content

Commit

Permalink
fix duplicate destinations, merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
janusec2 committed Aug 12, 2023
2 parents a12dfb1 + 7f02e18 commit da36606
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
10 changes: 8 additions & 2 deletions backend/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,18 +285,24 @@ func UpdateDestinations(app *models.Application, destinations []*models.Destinat
}
var err error
if destination.ID == 0 {
// new
destination.ID, err = data.DAL.InsertDestination(int64(destination.RouteType), destination.RequestRoute, destination.BackendRoute, destination.Destination, destination.PodsAPI, destination.PodPort, app.ID, destination.NodeID)
if err != nil {
utils.DebugPrintln("InsertDestination", err)
} else {
destination.Online = true
newDestinations = append(newDestinations, destination)
}
} else {
// update
err = data.DAL.UpdateDestinationNode(int64(destination.RouteType), destination.RequestRoute, destination.BackendRoute, destination.Destination, destination.PodsAPI, destination.PodPort, app.ID, destination.NodeID, destination.ID)
if err != nil {
utils.DebugPrintln("UpdateDestinationNode", err)
} else {
destination.Online = true
newDestinations = append(newDestinations, destination)
}
}
destination.Online = true
newDestinations = append(newDestinations, destination)
}
app.Destinations = newDestinations

Expand Down
10 changes: 9 additions & 1 deletion backend/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func InitDatabase() {

// v1.2.4 add constraint to access_stats
if !dal.ExistConstraint("access_stats", "stat_id") {
_ = dal.ExecSQL(`ALTER TABLE "access_stats" ADD CONSTRAINT "stat_id" unique ("app_id","url_path","stat_date")`)
_ = dal.ExecSQL(`ALTER TABLE "access_stats" ADD CONSTRAINT "stat_id" UNIQUE("app_id","url_path","stat_date")`)
//if err != nil {
//utils.DebugPrintln("InitDatabase ALTER TABLE access_stats add constraint", err)
//}
Expand All @@ -183,6 +183,14 @@ func InitDatabase() {
utils.DebugPrintln("InitDatabase ALTER TABLE applications add custom_headers", err)
}
}

// v1.4.2fix2 ALTER TABLE "destinations" ADD CONSTRAINT "unidest" UNIQUE("app_id","request_route","route_type","destination");
if !dal.ExistConstraint("destinations", "unidest") {
_ = dal.ExecSQL(`ALTER TABLE "destinations" ADD CONSTRAINT "unidest" UNIQUE("app_id","request_route","route_type","destination")`)
if err != nil {
utils.DebugPrintln("InitDatabase ALTER TABLE destinations add constraint", err)
}
}
}

// LoadAppConfiguration ...
Expand Down
15 changes: 9 additions & 6 deletions gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,16 +387,19 @@ func ReverseHandlerFunc(w http.ResponseWriter, r *http.Request) {
// var transport http.RoundTripper
transport := &http.Transport{
TLSHandshakeTimeout: 30 * time.Second,
ResponseHeaderTimeout: 30 * time.Second,
IdleConnTimeout: 30 * time.Second,
ExpectContinueTimeout: 5 * time.Second,
ExpectContinueTimeout: 10 * time.Second,
MaxIdleConns: 100,
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
conn, err := net.Dial("tcp", targetDest)
dest.CheckTime = nowTimeStamp
conn, err := net.Dial("tcp", targetDest)
if err != nil {
dest.Mutex.Lock()
defer dest.Mutex.Unlock()
dest.Online = false
utils.DebugPrintln("DialContext error", err)
timeout := time.Now().Unix() - nowTimeStamp
utils.DebugPrintln("DialContext error", err, timeout, "seconds")
if data.NodeSetting.SMTP.SMTPEnabled {
sendOfflineNotification(app, targetDest)
}
Expand All @@ -408,12 +411,12 @@ func ReverseHandlerFunc(w http.ResponseWriter, r *http.Request) {
return conn, err
},
DialTLS: func(network, addr string) (net.Conn, error) {
conn, err := net.Dial("tcp", targetDest)
dest.CheckTime = nowTimeStamp
conn, err := net.Dial("tcp", targetDest)
if err != nil {
dest.Online = false
dest.CheckTime = nowTimeStamp
utils.DebugPrintln("DialContext error", err)
timeout := time.Now().Unix() - nowTimeStamp
utils.DebugPrintln("DialTLS error", err, timeout, "seconds")
if data.NodeSetting.SMTP.SMTPEnabled {
sendOfflineNotification(app, targetDest)
}
Expand Down

0 comments on commit da36606

Please sign in to comment.