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: Adjust notifyCloseConnection to be a buffered channel to avoid blocking during exception handling #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nengwu765
Copy link

When closing the connection, an EOF error in the read method may trigger the shutdown operation. If notifyCloseConnection is unbuffered at this time, it will block graceful shutdown.

…locking during exception handling

When closing the connection, an EOF error in the read method may trigger the shutdown operation. If notifyCloseConnection is unbuffered at this time, it will block graceful shutdown.
@nengwu765
Copy link
Author

nengwu765 commented Oct 8, 2024

func (c *ConnectionWrapper) handleConnectionClose() {
	for {
		c.logger.Debug("handleConnectionClose is waiting for c.connected", nil)
		<-c.connected
		c.logger.Debug("handleConnectionClose is for connection or Pub/Sub close", nil)

		notifyCloseConnection := c.amqpConnection.NotifyClose(make(chan *amqp.Error))

		select {
		case <-c.closing:
			c.logger.Debug("Stopping handleConnectionClose", nil)
			c.connected = make(chan struct{})
			return
		case err := <-notifyCloseConnection:
			c.connected = make(chan struct{})
			c.logger.Error("Received close notification from AMQP, reconnecting", err, nil)
			c.reconnect()
		}
	}
}

when close happening, case <-c.closing done. notifyCloseConnection become a none consume channel。other gorutine send err to this channel will be blocked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant