Skip to content

Commit 0e4876e

Browse files
authored
feat: fix init panic (apache#540)
1 parent d9a8ffa commit 0e4876e

File tree

1 file changed

+22
-34
lines changed

1 file changed

+22
-34
lines changed

Diff for: pkg/datasource/sql/xa_resource_manager.go

+22-34
Original file line numberDiff line numberDiff line change
@@ -82,48 +82,36 @@ type XAResourceManager struct {
8282
}
8383

8484
func (xaManager *XAResourceManager) xaTwoPhaseTimeoutChecker() {
85-
var dbResource *DBResource
86-
xaManager.resourceCache.Range(func(key, value any) bool {
87-
if source, ok := value.(*DBResource); ok {
88-
dbResource = source
89-
}
90-
return false
91-
})
92-
93-
if dbResource.IsShouldBeHeld() {
94-
ticker := time.NewTicker(time.Second)
95-
for {
96-
select {
97-
case <-ticker.C:
98-
xaManager.resourceCache.Range(func(key, value any) bool {
99-
source, ok := value.(*DBResource)
100-
if !ok {
101-
return true
102-
}
103-
if source.IsShouldBeHeld() {
85+
ticker := time.NewTicker(time.Second)
86+
for {
87+
select {
88+
case <-ticker.C:
89+
xaManager.resourceCache.Range(func(key, value any) bool {
90+
source, ok := value.(*DBResource)
91+
if !ok {
92+
return true
93+
}
94+
if source.IsShouldBeHeld() {
95+
return true
96+
}
97+
98+
source.GetKeeper().Range(func(key, value any) bool {
99+
connectionXA, isConnectionXA := value.(*XAConn)
100+
if !isConnectionXA {
104101
return true
105102
}
106103

107-
source.GetKeeper().Range(func(key, value any) bool {
108-
connectionXA, isConnectionXA := value.(*XAConn)
109-
if !isConnectionXA {
110-
return true
104+
if time.Now().Sub(connectionXA.prepareTime) > xaManager.config.TwoPhaseHoldTime {
105+
if err := connectionXA.CloseForce(); err != nil {
106+
log.Errorf("Force close the xa xid:%s physical connection fail", connectionXA.txCtx.XID)
111107
}
112-
113-
if time.Now().Sub(connectionXA.prepareTime) > xaManager.config.TwoPhaseHoldTime {
114-
if err := connectionXA.CloseForce(); err != nil {
115-
log.Errorf("Force close the xa xid:%s physical connection fail", connectionXA.txCtx.XID)
116-
}
117-
}
118-
return true
119-
})
108+
}
120109
return true
121110
})
122-
}
111+
return true
112+
})
123113
}
124-
125114
}
126-
127115
}
128116

129117
func (xaManager *XAResourceManager) GetBranchType() branch.BranchType {

0 commit comments

Comments
 (0)