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

Fix example client to avoid deadlock in Close #123

Merged
merged 2 commits into from
Oct 1, 2022
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
18 changes: 6 additions & 12 deletions example_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func Example_consume() {
}

// This channel will receive a notification when a channel closed event
// happens. This must be different than Client.notifyChanClose because the
// happens. This must be different from Client.notifyChanClose because the
// library sends only one notification and Client.notifyChanClose already has
// a receiver in handleReconnect().
// Recommended to make it buffered to avoid deadlocks
Expand Down Expand Up @@ -273,8 +273,6 @@ func (client *Client) changeChannel(channel *amqp.Channel) {
}

// Push will push data onto the queue, and wait for a confirm.
// If no confirms are received until within the resendTimeout,
// it continuously re-sends messages until a confirm is received.
// This will block until the server sends a confirm. Errors are
// only returned if the push action itself fails, see UnsafePush.
func (client *Client) Push(data []byte) error {
Expand All @@ -292,15 +290,11 @@ func (client *Client) Push(data []byte) error {
}
continue
}
select {
case confirm := <-client.notifyConfirm:
if confirm.Ack {
client.logger.Println("Push confirmed!")
return nil
}
case <-time.After(resendDelay):
confirm := <-client.notifyConfirm
if confirm.Ack {
client.logger.Printf("Push confirmed [%d]!", confirm.DeliveryTag)
return nil
}
client.logger.Println("Push didn't confirm. Retrying...")
}
}

Expand Down Expand Up @@ -357,7 +351,7 @@ func (client *Client) Consume() (<-chan amqp.Delivery, error) {
)
}

// Close will cleanly shutdown the channel and connection.
// Close will cleanly shut down the channel and connection.
func (client *Client) Close() error {
if !client.isReady {
return errAlreadyClosed
Expand Down