Repository navigation
Fix data race while accessing connection in partitionProducer - #701
Merged
Merged
Conversation
Signed-off-by: xiaolongran <[email protected]>
Member
Author
|
cc @dferstay PTAL thanks |
Signed-off-by: xiaolongran <[email protected]>
Signed-off-by: xiaolongran <[email protected]>
freeznet
reviewed
Jan 11, 2022
| p.log.Warnf("Received ack for %v on sequenceId %v - expected: %v, closing connection", response.GetMessageId(), | ||
| response.GetSequenceId(), pi.sequenceID) | ||
| p.cnx.Close() | ||
| p._getConn().Close() |
Contributor
There was a problem hiding this comment.
maybe clean up the cached connection when the cnx is closed? otherwise _getConn() will return a closed connection.
Member
Author
There was a problem hiding this comment.
@freeznet Looking at the implementation of the current Close method, when triggering the logic of Close, the state of the current connection will first be set to connectionClosed. When GetConnection() is executed, if the state of the connection is detected to be closed, the connection will be removed from the cache.
func (c *connection) Close() {
c.closeOnce.Do(func() {
c.Lock()
cnx := c.cnx
c.Unlock()
c.changeState(connectionClosed)
if conn.closed() {
delete(p.connections, key)
p.log.Infof("Removed connection from pool key=%s logical_addr=%+v physical_addr=%+v",
key, conn.logicalAddr, conn.physicalAddr)
conn = nil // set to nil so we create a new one
}
congbobo184
approved these changes
Jan 12, 2022
freeznet
approved these changes
Jan 12, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Signed-off-by: xiaolongran [email protected]
Motivation
In #700, we use a separate go rutine to handle the logic of reconnect, so here you may encounter the same data race problem as #535
Modifications
Now, the conn field is read and written atomically; avoiding race conditions.