Skip to content

Commit fb4cc6f

Browse files
fix dead lock (#21279)
fix dead lock Approved by: @ouyuanning
1 parent 97ec151 commit fb4cc6f

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

pkg/txn/client/client.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,9 @@ func (client *txnClient) removeFromWaitActiveLocked(txnID []byte) bool {
743743

744744
func (client *txnClient) waitMarkAllActiveAbortedLocked() {
745745
if client.mu.waitMarkAllActiveAbortedC != nil {
746-
<-client.mu.waitMarkAllActiveAbortedC
746+
c := client.mu.waitMarkAllActiveAbortedC
747+
client.mu.Unlock()
748+
<-c
749+
client.mu.Lock()
747750
}
748751
}

pkg/txn/client/client_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,3 +275,16 @@ func TestNewWithUpdateSnapshotTimeout(t *testing.T) {
275275
assert.Equal(t, 0, len(v.mu.waitActiveTxns))
276276
v.mu.Unlock()
277277
}
278+
279+
func TestWaitAbortMarked(t *testing.T) {
280+
c := make(chan struct{})
281+
tc := &txnClient{}
282+
tc.mu.waitMarkAllActiveAbortedC = c
283+
tc.mu.state = normal
284+
tc.mu.activeTxns = map[string]*txnOperator{}
285+
go func() {
286+
close(c)
287+
}()
288+
op := &txnOperator{}
289+
require.NoError(t, tc.openTxn(op))
290+
}

pkg/txn/client/operator.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ import (
2424
"sync/atomic"
2525
"time"
2626

27-
"go.uber.org/zap"
28-
2927
"github.com/matrixorigin/matrixone/pkg/common/log"
3028
"github.com/matrixorigin/matrixone/pkg/common/moerr"
3129
"github.com/matrixorigin/matrixone/pkg/common/runtime"
@@ -38,6 +36,7 @@ import (
3836
"github.com/matrixorigin/matrixone/pkg/txn/rpc"
3937
"github.com/matrixorigin/matrixone/pkg/txn/util"
4038
v2 "github.com/matrixorigin/matrixone/pkg/util/metric/v2"
39+
"go.uber.org/zap"
4140
)
4241

4342
var (

0 commit comments

Comments
 (0)