Skip to content

Commit

Permalink
Merge pull request #1415 from openziti/fix-xctrl-startup-race
Browse files Browse the repository at this point in the history
Ensure control chan is available before starting xctrls. Fixes #1414
  • Loading branch information
plorenz authored Oct 11, 2023
2 parents 76b92ab + c79deb7 commit 1678b87
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
29 changes: 15 additions & 14 deletions router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/openziti/ziti/common/config"
"github.com/openziti/ziti/router/link"
"github.com/openziti/foundation/v2/debugz"
"github.com/openziti/foundation/v2/goroutines"
"github.com/openziti/xweb/v2"
"github.com/openziti/ziti/common/config"
"github.com/openziti/ziti/router/link"
metrics2 "github.com/rcrowley/go-metrics"
"io/fs"
"os"
Expand All @@ -39,6 +39,12 @@ import (
"github.com/AppsFlyer/go-sundheit/checks"
"github.com/michaelquigley/pfxlog"
"github.com/openziti/channel/v2"
"github.com/openziti/foundation/v2/concurrenz"
"github.com/openziti/foundation/v2/errorz"
"github.com/openziti/foundation/v2/versions"
"github.com/openziti/identity"
"github.com/openziti/metrics"
"github.com/openziti/transport/v2"
"github.com/openziti/ziti/common/health"
fabricMetrics "github.com/openziti/ziti/common/metrics"
"github.com/openziti/ziti/common/pb/ctrl_pb"
Expand All @@ -55,12 +61,6 @@ import (
"github.com/openziti/ziti/router/xgress_transport_udp"
"github.com/openziti/ziti/router/xlink"
"github.com/openziti/ziti/router/xlink_transport"
"github.com/openziti/foundation/v2/concurrenz"
"github.com/openziti/foundation/v2/errorz"
"github.com/openziti/foundation/v2/versions"
"github.com/openziti/identity"
"github.com/openziti/metrics"
"github.com/openziti/transport/v2"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"google.golang.org/protobuf/proto"
Expand Down Expand Up @@ -531,12 +531,6 @@ func (self *Router) startControlPlane() error {

self.ctrls.UpdateControllerEndpoints(endpoints)

for _, x := range self.xrctrls {
if err := x.Run(self); err != nil {
return err
}
}

self.metricsReporter = fabricMetrics.NewControllersReporter(self.ctrls)
self.metricsRegistry.StartReporting(self.metricsReporter, self.config.Metrics.ReportInterval, self.config.Metrics.MessageQueueSize)

Expand All @@ -549,6 +543,13 @@ func (self *Router) startControlPlane() error {
}
})

_ = self.ctrls.AnyValidCtrlChannel()
for _, x := range self.xrctrls {
if err := x.Run(self); err != nil {
return err
}
}

return nil
}

Expand Down
26 changes: 17 additions & 9 deletions router/xgress_edge_tunnel/fabric.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ import (
"github.com/openziti/channel/v2"
"github.com/openziti/channel/v2/protobufs"
"github.com/openziti/edge-api/rest_model"
"github.com/openziti/ziti/common/pb/edge_ctrl_pb"
"github.com/openziti/ziti/router/xgress_common"
"github.com/openziti/ziti/tunnel"
"github.com/openziti/ziti/common/build"
"github.com/openziti/ziti/common/ctrl_msg"
"github.com/openziti/ziti/router/xgress"
"github.com/openziti/foundation/v2/concurrenz"
"github.com/openziti/foundation/v2/errorz"
"github.com/openziti/sdk-golang/ziti"
"github.com/openziti/sdk-golang/ziti/edge"
"github.com/openziti/sdk-golang/ziti/sdkinfo"
"github.com/openziti/secretstream/kx"
"github.com/openziti/ziti/common/build"
"github.com/openziti/ziti/common/ctrl_msg"
"github.com/openziti/ziti/common/pb/edge_ctrl_pb"
"github.com/openziti/ziti/router/xgress"
"github.com/openziti/ziti/router/xgress_common"
"github.com/openziti/ziti/tunnel"
cmap "github.com/orcaman/concurrent-map/v2"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -168,12 +168,20 @@ func (self *fabricProvider) authenticate() error {
}

ctrlMap := self.factory.ctrls.GetAll()
results := newAuthResults(len(ctrlMap))
ctrlChMap := map[string]channel.Channel{}
for k, v := range ctrlMap {
ctrlChMap[k] = v.Channel()
}
if len(ctrlChMap) == 0 {
ctrlCh := self.factory.ctrls.AnyValidCtrlChannel()
ctrlChMap[ctrlCh.Id()] = ctrlCh
}
results := newAuthResults(len(ctrlChMap))
for k, v := range ctrlChMap {
ctrlId := k
ctrl := v
ctrlCh := v
go func() {
respMsg, err := protobufs.MarshalTyped(request).WithTimeout(30 * time.Second).SendForReply(ctrl.Channel())
respMsg, err := protobufs.MarshalTyped(request).WithTimeout(30 * time.Second).SendForReply(ctrlCh)

resp := &edge_ctrl_pb.CreateApiSessionResponse{}
if err = xgress_common.GetResultOrFailure(respMsg, err, resp); err != nil {
Expand Down

0 comments on commit 1678b87

Please sign in to comment.