@@ -116,17 +116,21 @@ public void FailoverTo(IEnumerable<string> readWriteHosts, IEnumerable<string> r
116116 /// <returns></returns>
117117 public IRedisClient GetClient ( )
118118 {
119+ int section = 1 ;
119120 try
120121 {
121- var inactivePoolIndex = - 1 ;
122+ var inactivePoolIndex = - 1 ;
122123 lock ( clients )
123124 {
125+ section = 2 ;
124126 AssertValidPool ( ) ;
125127
128+ section = 3 ;
126129 RedisClient inActiveClient ;
127130 //-1 when no available clients otherwise index of reservedSlot or existing Client
128131 inactivePoolIndex = GetInActiveClient ( out inActiveClient ) ;
129132
133+ section = 4 ;
130134 //inActiveClient != null only for Valid InActive Clients
131135 if ( inActiveClient != null )
132136 {
@@ -140,28 +144,36 @@ public IRedisClient GetClient()
140144 //Reaches here when there's no Valid InActive Clients
141145 try
142146 {
147+ section = 5 ;
143148 //inactivePoolIndex == -1 || index of reservedSlot || index of invalid client
144- var existingClient = inactivePoolIndex >= 0 && inactivePoolIndex < clients . Length
145- ? clients [ inactivePoolIndex ]
149+ var existingClient = inactivePoolIndex >= 0 && inactivePoolIndex < clients . Length
150+ ? clients [ inactivePoolIndex ]
146151 : null ;
147152
153+ section = 5 ;
148154 if ( existingClient != null && existingClient != reservedSlot && existingClient . HadExceptions )
149155 {
156+ section = 6 ;
150157 RedisState . DeactivateClient ( existingClient ) ;
151158 }
152159
153- var newClient = InitNewClient ( RedisResolver . CreateMasterClient ( Math . Max ( inactivePoolIndex , 0 ) ) ) ;
160+ section = 7 ;
161+ var newClient = RedisResolver . CreateMasterClient ( Math . Max ( inactivePoolIndex , 0 ) ) ;
162+ section = 8 ;
163+ newClient = InitNewClient ( newClient ) ;
154164
155165 //Put all blocking I/O or potential Exceptions before lock
156166 lock ( clients )
157167 {
158168 //Create new client outside of pool when max pool size exceeded
159169 //Reverting free-slot not needed when -1 since slwo wasn't reserved or
160170 //when existingClient changed (failover) since no longer reserver
161- var stillReserved = inactivePoolIndex >= 0 && inactivePoolIndex < clients . Length &&
162- clients [ inactivePoolIndex ] == existingClient ;
171+ section = 9 ;
172+ var stillReserved = inactivePoolIndex >= 0 && inactivePoolIndex < clients . Length &&
173+ clients [ inactivePoolIndex ] == existingClient ;
163174 if ( inactivePoolIndex == - 1 || ! stillReserved )
164175 {
176+ section = 10 ;
165177 if ( Log . IsDebugEnabled )
166178 Log . Debug ( "clients[inactivePoolIndex] != existingClient: {0}" . Fmt ( ! stillReserved ? "!stillReserved" : "-1" ) ) ;
167179
@@ -172,6 +184,7 @@ public IRedisClient GetClient()
172184 return newClient ;
173185 }
174186
187+ section = 11 ;
175188 poolIndex ++ ;
176189 clients [ inactivePoolIndex ] = newClient ;
177190 return newClient ;
@@ -182,6 +195,7 @@ public IRedisClient GetClient()
182195 //Revert free-slot for any I/O exceptions that can throw (before lock)
183196 lock ( clients )
184197 {
198+ section = 12 ;
185199 if ( inactivePoolIndex >= 0 && inactivePoolIndex < clients . Length )
186200 {
187201 clients [ inactivePoolIndex ] = null ;
@@ -190,9 +204,20 @@ public IRedisClient GetClient()
190204 throw ;
191205 }
192206 }
207+ catch ( IndexOutOfRangeException ex )
208+ {
209+ throw new Exception ( "Error after section: " + section , ex ) ;
210+ }
193211 finally
194212 {
195- RedisState . DisposeExpiredClients ( ) ;
213+ try
214+ {
215+ RedisState . DisposeExpiredClients ( ) ;
216+ }
217+ catch ( IndexOutOfRangeException ex )
218+ {
219+ throw new Exception ( "Error at RedisState.DisposeExpiredClients()" , ex ) ;
220+ }
196221 }
197222 }
198223
0 commit comments