Skip to content

do not panic during chunk dispatching if consumer suddenly closed #393

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

Merged
merged 4 commits into from
May 7, 2025
Merged
Changes from 2 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
16 changes: 12 additions & 4 deletions pkg/stream/server_frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package stream
import (
"bufio"
"bytes"
"github.com/rabbitmq/rabbitmq-stream-go-client/pkg/amqp"
"github.com/rabbitmq/rabbitmq-stream-go-client/pkg/logs"
"hash/crc32"
"io"
"time"

"github.com/rabbitmq/rabbitmq-stream-go-client/pkg/amqp"
"github.com/rabbitmq/rabbitmq-stream-go-client/pkg/logs"
)

type ReaderProtocol struct {
Expand Down Expand Up @@ -281,7 +282,6 @@ func (c *Client) queryPublisherSequenceFrameHandler(readProtocol *ReaderProtocol
res.data <- sequence
}
func (c *Client) handleDeliver(r *bufio.Reader) {

subscriptionId := readByte(r)
consumer, err := c.coordinator.GetConsumerById(subscriptionId)
consumerFound := err == nil
Expand Down Expand Up @@ -406,8 +406,16 @@ func (c *Client) handleDeliver(r *bufio.Reader) {

// dispatch the messages with offset to the consumer
chunk.offsetMessages = batchConsumingMessages
logs.LogDebug("Dispatching %d messages to consumer %d", len(batchConsumingMessages), subscriptionId)
if consumer.getStatus() == open {
consumer.chunkForConsumer <- chunk
select {
case consumer.chunkForConsumer <- chunk:
return
default:
logs.LogDebug("The consumer %s for the stream %s reports as open but is probably "+
"closed during chunk dispatching. Messages won't be dispatched. ",
consumer.GetName(), consumer.GetStreamName())
}
} else {
logs.LogDebug("The consumer %s for the stream %s is closed during the chunk dispatching. "+
"Messages won't dispatched", consumer.GetName(), consumer.GetStreamName())
Expand Down