Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed deadlock when handling multiple stream entries errors #576

Merged
merged 1 commit into from
Nov 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions server/leader_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -886,10 +886,10 @@ func (lc *leaderController) handleWriteStream(stream proto.OxiaClient_WriteStrea
req, err := stream.Recv()

if err != nil {
closeCh <- err
sendNonBlocking(closeCh, err)
return
} else if req == nil {
closeCh <- errors.New("stream closed")
sendNonBlocking(closeCh, errors.New("stream closed"))
return
}

Expand All @@ -908,7 +908,7 @@ func (lc *leaderController) handleWalSynced(stream proto.OxiaClient_WriteStreamS
offset int64, timestamp uint64, err error, timer metrics.Timer) {
if err != nil {
timer.Done()
closeCh <- err
sendNonBlocking(closeCh, err)
return
}

Expand All @@ -917,13 +917,13 @@ func (lc *leaderController) handleWalSynced(stream proto.OxiaClient_WriteStreamS
}, func(response *proto.WriteResponse, err error) {
if err != nil {
timer.Done()
closeCh <- err
sendNonBlocking(closeCh, err)
return
}

if err = stream.Send(response); err != nil {
timer.Done()
closeCh <- err
sendNonBlocking(closeCh, err)
return
}
timer.Done()
Expand Down Expand Up @@ -1136,3 +1136,10 @@ func checkStatusIsLeader(actual proto.ServingStatus) error {
}
return nil
}

func sendNonBlocking(ch chan error, err error) {
select {
case ch <- err:
default:
}
}
Loading