forked from fl00r/go-tarantool-1.6
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bugfix: prevent recreate connection after Close()
The ConnectionPool.checker() goroutine may still work some time after ConnectionPool.Close() call. It may lead to re-open connection in a concurrent closing pool. The connection still opened after the pool is closed. The patch adds RWLock to protect blocks which work with anyPool, roPool and rwPool. We don't need to protect regular requests because in the worst case, we will send a request into a closed connection. It can happen for other reasons and it seems like we can't avoid it. So it is an expected behavior. Closes #208
- Loading branch information
1 parent
0c6a81a
commit adb2bfd
Showing
4 changed files
with
78 additions
and
42 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package connection_pool | ||
|
||
import ( | ||
"sync/atomic" | ||
) | ||
|
||
// pool state | ||
type state uint32 | ||
|
||
const ( | ||
unknownState state = iota | ||
connectedState | ||
closedState | ||
) | ||
|
||
func (s *state) set(news state) { | ||
atomic.StoreUint32((*uint32)(s), uint32(news)) | ||
} | ||
|
||
func (s *state) cas(olds, news state) bool { | ||
return atomic.CompareAndSwapUint32((*uint32)(s), uint32(olds), uint32(news)) | ||
} | ||
|
||
func (s *state) get() state { | ||
return state(atomic.LoadUint32((*uint32)(s))) | ||
} |