Skip to content

Commit 4dad22a

Browse files
Resolve a deadlock (#603)
* Resolve a deadlock * Update connection.go * Update OnSuccess to lock pool before locking the connection * Transport: Add lock to prevent connection from being resurrected multiple times --------- Co-authored-by: Laurent Saint-Félix <[email protected]>
1 parent 76a1c93 commit 4dad22a

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

estransport/connection.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,23 +138,25 @@ func (cp *statusConnectionPool) Next() (*Connection, error) {
138138
// OnSuccess marks the connection as successful.
139139
//
140140
func (cp *statusConnectionPool) OnSuccess(c *Connection) error {
141-
c.Lock()
142-
defer c.Unlock()
143-
144141
// Short-circuit for live connection
142+
c.Lock()
145143
if !c.IsDead {
144+
c.Unlock()
146145
return nil
147146
}
148-
149-
c.markAsHealthy()
147+
c.Unlock()
150148

151149
cp.Lock()
152150
defer cp.Unlock()
151+
152+
c.Lock()
153+
defer c.Unlock()
154+
155+
c.markAsHealthy()
153156
return cp.resurrect(c, true)
154157
}
155158

156159
// OnFailure marks the connection as failed.
157-
//
158160
func (cp *statusConnectionPool) OnFailure(c *Connection) error {
159161
cp.Lock()
160162
defer cp.Unlock()

0 commit comments

Comments
 (0)