/// <summary> /// It is assumed that this method is only called from inside an active lock. /// </summary> private Driver GetPooledConnection() { Driver driver = null; // if we don't have an idle connection but we have room for a new // one, then create it here. lock ((idlePool as ICollection).SyncRoot) { if (HasIdleConnections) { driver = idlePool.Dequeue(); } } // Obey the connection timeout if (driver != null) { try { driver.ResetTimeout((int)Settings.ConnectionTimeout * 1000); } catch (Exception) { driver.Close(); driver = null; } } if (driver != null) { // first check to see that the server is still alive if (!driver.Ping()) { driver.Close(); driver = null; } else if (settings.ConnectionReset) { // if the user asks us to ping/reset pooled connections // do so now driver.Reset(); } } if (driver == null) { driver = CreateNewPooledConnection(); } Debug.Assert(driver != null); lock ((inUsePool as ICollection).SyncRoot) { inUsePool.Add(driver); int currentlyInUse = inUsePool.Count; if (currentlyInUse > maxUsedConnections) { maxUsedConnections = currentlyInUse; } } return(driver); }
internal void HandleTimeoutOrThreadAbort(Exception ex) { bool isFatal = false; if (_isKillQueryConnection) { // Special connection started to cancel a query. // Abort will prevent recursive connection spawning Abort(); if (ex is TimeoutException) { Throw(new MySqlException(Resources.Timeout, true, ex)); } else { return; } } try { // Do a fast cancel.The reason behind small values for connection // and command timeout is that we do not want user to wait longer // after command has already expired. // Microsoft's SqlClient seems to be using 5 seconds timeouts // here as well. // Read the error packet with "interrupted" message. CancelQuery(5); driver.ResetTimeout(5000); if (Reader != null) { Reader.Close(); Reader = null; } } catch (Exception ex2) { MySqlTrace.LogWarning(ServerThread, "Could not kill query, " + " aborting connection. Exception was " + ex2.Message); Abort(); isFatal = true; } if (ex is TimeoutException) { Throw(new MySqlException(Resources.Timeout, isFatal, ex)); } }
/// <summary> /// Clears query timeout, allowing next SetCommandTimeout() to succeed. /// </summary> internal void ClearCommandTimeout() { if (!hasBeenOpen) { return; } _commandTimeout = 0; driver?.ResetTimeout(0); }
private Driver GetPooledConnection() { Driver driver = null; lock (((ICollection)this.idlePool).SyncRoot) { if (this.HasIdleConnections) { driver = this.idlePool.Dequeue(); } } if (driver != null) { try { driver.ResetTimeout((int)(this.Settings.ConnectionTimeout * 1000u)); } catch (Exception) { driver.Close(); driver = null; } } if (driver != null) { if (!driver.Ping()) { driver.Close(); driver = null; } else { if (this.settings.ConnectionReset) { driver.Reset(); } } } if (driver == null) { driver = this.CreateNewPooledConnection(); } lock (((ICollection)this.inUsePool).SyncRoot) { this.inUsePool.Add(driver); } return(driver); }
/// <summary> /// It is assumed that this method is only called from inside an active lock. /// </summary> private Driver GetPooledConnection() { Driver driver = null; // if we don't have an idle connection but we have room for a new // one, then create it here. lock ((idlePool as ICollection).SyncRoot) { if (HasIdleConnections) { driver = idlePool.Dequeue(); } } // Obey the connection timeout if (driver != null) { try { driver.ResetTimeout((int)Settings.ConnectionTimeout * 1000); } catch (Exception) { driver.Close(); driver = null; } } if (driver == null) { driver = CreateNewPooledConnection(); } Debug.Assert(driver != null); lock ((inUsePool as ICollection).SyncRoot) { inUsePool.Add(driver); } return(driver); }