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

Log errors after failing to send acks #3855

Merged
merged 4 commits into from
Nov 13, 2021
Merged
Changes from 1 commit
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
14 changes: 10 additions & 4 deletions src/msg/consumer/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"sync"
"time"

"go.uber.org/zap"

"github.com/m3db/m3/src/msg/generated/proto/msgpb"
"github.com/m3db/m3/src/msg/protocol/proto"
"github.com/m3db/m3/src/x/clock"
Expand Down Expand Up @@ -168,8 +170,12 @@ func (c *consumer) tryAck(m msgpb.Metadata) {
c.Unlock()
return
}
if err := c.encodeAckWithLock(ackLen); err != nil {
c.conn.Close()
if err := c.sendAckWithLock(ackLen); err != nil {
c.opts.InstrumentOptions().Logger().Error("failed to send ack. closing connection.", zap.Error(err))
if err := c.conn.Close(); err != nil {
c.opts.InstrumentOptions().Logger().Error("failed to close connection after failed ack.",
zap.Error(err))
}
}
c.Unlock()
}
Expand All @@ -192,13 +198,13 @@ func (c *consumer) ackUntilClose() {
func (c *consumer) tryAckAndFlush() {
c.Lock()
if ackLen := len(c.ackPb.Metadata); ackLen > 0 {
c.encodeAckWithLock(ackLen)
c.sendAckWithLock(ackLen)
}
c.w.Flush()
c.Unlock()
}

func (c *consumer) encodeAckWithLock(ackLen int) error {
func (c *consumer) sendAckWithLock(ackLen int) error {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seemed like a more appropriate method name, since it actually sends the ack over the network.

err := c.encoder.Encode(&c.ackPb)
c.ackPb.Metadata = c.ackPb.Metadata[:0]
if err != nil {
Expand Down