///<summary> /// This method is responsible to handle all protocol messages sent from the backend. /// It holds all the logic to do it. /// To exchange data, it uses a Mediator object from which it reads/writes information /// to handle backend requests. /// </summary> /// internal IEnumerable <IServerResponseObject> ProcessBackendResponsesEnum(NpgsqlConnector context) { try { // Flush buffers to the wire. context.Stream.Flush(); // Process commandTimeout behavior. if ((context.Mediator.BackendCommandTimeout > 0) && (!CheckForContextSocketAvailability(context, SelectMode.SelectRead))) { // If timeout occurs when establishing the session with server then // throw an exception instead of trying to cancel query. This helps to prevent loop as // CancelRequest will also try to stablish a connection and sends commands. if (!((this is NpgsqlStartupState || this is NpgsqlConnectedState))) { try { context.CancelRequest(); ProcessAndDiscardBackendResponses(context); } catch (Exception) { } // We should have gotten an error from CancelRequest(). Whether we did or not, what we // really have is a timeout exception, and that will be less confusing to the user than // "operation cancelled by user" or similar, so whatever the case, that is what we'll throw. // Changed message again to report about the two possible timeouts: connection or command // as the establishment timeout only was confusing users when the timeout was a command timeout. } throw new NpgsqlException("Exception_ConnectionOrCommandTimeout"); } return(ProcessBackendResponses(context)); } catch (ThreadAbortException) { try { context.CancelRequest(); context.Close(); } catch {} throw; } }
/// <summary> /// Attempts to cancel the execution of a <see cref="NpgsqlCommand">NpgsqlCommand</see>. /// </summary> /// <remarks>This Method isn't implemented yet.</remarks> public override void Cancel() { NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "Cancel"); try { // get copy for thread safety of null test NpgsqlConnector connector = Connector; if (connector != null) { connector.CancelRequest(); } } catch (IOException) { Connection.ClearPool(); } catch (NpgsqlException) { // Cancel documentation says the Cancel doesn't throw on failure } }