Skip to content

Commit 7455deb

Browse files
authored
Merge pull request #3779 from openziti/bug-fixes
Fix a panic and a deadlock
2 parents f88b6ea + 34022b5 commit 7455deb

File tree

7 files changed

+33
-11
lines changed

7 files changed

+33
-11
lines changed

.github/workflows/backward-compatibility.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ jobs:
6464
go install -tags=all,tests ./...
6565
6666
- name: Create Test Environment
67+
env:
68+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6769
shell: bash
6870
run: |
6971
echo "ZITI_ROOT=$(go env GOPATH)/bin" >> "$GITHUB_ENV"

.github/workflows/validation-test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ jobs:
6262
go install -tags=all,tests ./...
6363
6464
- name: Create Test Environment
65+
env:
66+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6567
shell: bash
6668
run: |
6769
echo "ZITI_ROOT=$(go env GOPATH)/bin" >> "$GITHUB_ENV"

controller/model/path.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ type Path struct {
3131
TerminatorRemoteAddr string
3232
}
3333

34+
func (self *Path) IsValid() bool {
35+
return self != nil && len(self.Nodes) > 0
36+
}
37+
3438
func (self *Path) Cost(minRouterCost uint16) int64 {
3539
var cost int64
3640
for _, l := range self.Links {

controller/network/network.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,7 @@ func (network *Network) CreateCircuit(params model.CreateCircuitParams) (*model.
589589
Id: circuitId,
590590
ClientId: clientId.Token,
591591
ServiceId: serviceId,
592+
Path: &model.Path{}, // empty until the circuit is built
592593
}
593594

594595
// Reserve the circuit ID in the map to prevent collisions and protect routing.
@@ -1093,14 +1094,17 @@ func (network *Network) rerouteLink(l *model.Link, deadline time.Time) error {
10931094
func (network *Network) rerouteCircuitWithTries(circuit *model.Circuit, retries int) bool {
10941095
log := pfxlog.Logger().WithField("circuitId", circuit.Id)
10951096

1096-
for i := 0; i < retries; i++ {
1097-
deadline := time.Now().Add(config.DefaultOptionsRouteTimeout)
1098-
err := network.rerouteCircuit(circuit, deadline)
1099-
if err == nil {
1100-
return true
1101-
}
1097+
// Path is nil for reserved circuits that haven't been built yet
1098+
if circuit.Path.IsValid() {
1099+
for i := 0; i < retries; i++ {
1100+
deadline := time.Now().Add(config.DefaultOptionsRouteTimeout)
1101+
err := network.rerouteCircuit(circuit, deadline)
1102+
if err == nil {
1103+
return true
1104+
}
11021105

1103-
log.WithError(err).WithField("attempt", i).Error("error re-routing circuit")
1106+
log.WithError(err).WithField("attempt", i).Error("error re-routing circuit")
1107+
}
11041108
}
11051109

11061110
if err := network.RemoveCircuit(circuit.Id, true); err != nil {

controller/network/smart.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ func (network *Network) getRerouteCandidates() []*newCircuitPath {
7171
circuitCosts := make(map[string]int64)
7272
var orderedCircuits []string
7373
for _, circuit := range circuits {
74-
circuitCosts[circuit.Id] = network.calculateCircuitCost(circuit.Path)
75-
orderedCircuits = append(orderedCircuits, circuit.Id)
74+
if circuit.Path.IsValid() {
75+
circuitCosts[circuit.Id] = network.calculateCircuitCost(circuit.Path)
76+
orderedCircuits = append(orderedCircuits, circuit.Id)
77+
}
7678
}
7779

7880
sort.SliceStable(orderedCircuits, func(i, j int) bool {

router/state/manager.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,14 @@ func (self *ManagerImpl) SetRouterDataModel(model *common.RouterDataModel, reset
957957

958958
self.routerDataModel.Store(model)
959959

960+
// Clear the replace-in-progress flag before syncing subscribers. The model is
961+
// fully stored at this point, so RouterDataModel() can safely return it.
962+
// SyncAllSubscribers triggers subscriber notifications (e.g., service hosting)
963+
// that call RouterDataModel(). If the flag is still set, those calls spin-wait
964+
// for it to clear, which can't happen until this function returns, causing a
965+
// deadlock.
966+
self.rmdReplaceInProgress.Store(false)
967+
960968
if index < existingIndex {
961969
self.env.GetIndexWatchers().NotifyOfIndexReset()
962970
}

zititest/models/circuit-test/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import (
3636
"github.com/openziti/ziti/zititest/zitilab/validations"
3737
)
3838

39-
var DefaultVersion = "v1.7.0"
39+
var DefaultVersion = ""
4040
var ClientRoutersVersion = ""
4141
var HostRoutersVersion = ""
4242

@@ -48,7 +48,7 @@ const (
4848
TestModeHostBackwardsCompatibility = "host-backwards-compatibility"
4949
)
5050

51-
var mode testMode = TestModeHostBackwardsCompatibility
51+
var mode testMode = TestModeDefault
5252

5353
var entityCounts = map[string]uint32{
5454
"loop-client": 1,

0 commit comments

Comments
 (0)