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

feat(server): return actual error when context done #581

Merged
merged 3 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions server/leader_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import (
"github.com/streamnative/oxia/server/wal"
)

var ErrLeaderClosed = errors.New("the leader has been closed")

type GetResult struct {
Response *proto.GetResponse
Err error
Expand Down Expand Up @@ -874,9 +876,9 @@ func (lc *leaderController) WriteStream(stream proto.OxiaClient_WriteStreamServe
case err := <-closeStreamCh:
return err
case <-stream.Context().Done():
return context.Canceled
return stream.Context().Err()
case <-lc.ctx.Done():
return context.Canceled
return errors.Wrap(ErrLeaderClosed, lc.ctx.Err().Error())
}
}

Expand Down
19 changes: 11 additions & 8 deletions server/public_rpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,17 @@ func (s *publicRpcServer) WriteStream(stream proto.OxiaClient_WriteStreamServer)
return err
}

err = lc.WriteStream(stream)
if err != nil &&
!errors.Is(err, io.EOF) &&
!errors.Is(err, context.Canceled) {
log.Warn(
"Write stream failed",
slog.Any("error", err),
)
if err = lc.WriteStream(stream); err != nil {
if errors.Is(err, io.EOF) || errors.Is(err, context.Canceled) {
log.Info("Write stream has been closed")
return nil
}
if errors.Is(err, ErrLeaderClosed) {
log.Info("Write stream has been closed by leader closed")
return err
}
log.Warn("Write stream has been closed by error", slog.Any("error", err))
return err
}
return err
}
Expand Down
Loading