Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query marked as active in MON$STATEMENTS after cancelling the query [CORE1578] #1996

Closed
firebird-automations opened this issue Nov 8, 2007 · 10 comments

Comments

@firebird-automations
Copy link
Collaborator

Submitted by: Thomas Steinmaurer (tsteinmaurer)

Query cancelling seems to work fine by invoking a DELETE statement on
MON$STATEMENTS, but I don't get the expected result when re-querying the
MON$STATEMENTS table, because the statement is still listed there,
although possibly with another MON$STATEMENT_ID than the one which has
been used when executing the DELETE statement.

Test case:

SET TERM ^^ ;
CREATE PROCEDURE P_ENDLESSLOOP (
TO_VALUE Integer DEFAULT 1000000)
returns (
I Integer)
AS
begin
i = 1;
while (i <= to_value) do
begin
suspend;
i = i + 1;
end
end
^^
SET TERM ; ^^

COMMIT;

Running the selectable SP with e.g.:

SELECT * FROM P_ENDLESSLOOP;

In another isql session, I cancel the query with a DELETE statement on
MON$STATEMENTS. I get the follow cancelling message in the first isql
session:

ERROR:
Statement failed, SQLCODE = -901
operation was cancelled

Now, I re-query the MON$STATEMENTS table in another isql session. I
still see the cancelled statement with MON$STATE = 1, but possibly with
another MON$STATEMENT_ID. This guy will disappear when I commit the
transaction in the isql session with the cancelled query.

@firebird-automations
Copy link
Collaborator Author

Modified by: @dyemanov

assignee: Dmitry Yemanov [ dimitr ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @dyemanov

Fix Version: 2.1 RC1 [ 10201 ]

@firebird-automations
Copy link
Collaborator Author

Commented by: @dyemanov

After investigating this issue more, I tend to conclude that everything is as designed.

An active state (RDB$STATE = 1) doesn't necessarily mean a statement running inside the engine. This state reflects also open cursors that are being fetched by the clients. And this state remains until the cursor is closed. In particular, even if the client fetches just the first record and stalls forever (keeping the cursor open), the statement will be marked as active. Practically, this means that a canceled fetch will be also marked as active until the client processes the error code and closes the cursor (releases the statement handle).

This is exactly what happens with the local protocol or with an older fbclient -- the monitoring shows you RDB$STATE = 0, because ISQL immediately closes the cursor in the case of error. However, if you use v2.1 fbclient and TCP connection, you see RDB$STATE = 1, as reported in this ticket. This is due to the deferred packets delivery implemented in v2.1 -- the client doesn't send the op_dsql_free packet immediately, instead it's queued to be sent along with the next packet. If you leave the ISQL session intact, it doesn't happen and RDB$STATE remains active. If you issue commit or disconnect, RDB$STATE changes. In the real world, most applications would rollback in the case of cancellation, thus the problem will not be visible.

I think a possible solution for this issue would be a more detailed states encoding, i.e. distinguish between really ACTIVE and STALLED/SUSPENDED, or to introduce a CANCELED state. But I'm afraid this has to wait until v2.5.

Thomas, would you prefer this ticket to be closed as "won't fix" or kept open but scheduled for v2.5?

@firebird-automations
Copy link
Collaborator Author

Modified by: @dyemanov

Fix Version: 2.1 RC1 [ 10201 ] =>

@firebird-automations
Copy link
Collaborator Author

Modified by: @pcisar

Workflow: jira [ 13393 ] => Firebird [ 14062 ]

@firebird-automations
Copy link
Collaborator Author

Commented by: Thomas Steinmaurer (tsteinmaurer)

Feel free to close it as "won't fix", if you add a new one for a more detailed state encoding. ;-)

@firebird-automations
Copy link
Collaborator Author

Commented by: @dyemanov

v2.5 has introduced the "stalled" state mentioned in this ticket, thus I resolve it.

@firebird-automations
Copy link
Collaborator Author

Modified by: @dyemanov

status: Open [ 1 ] => Resolved [ 5 ]

resolution: Fixed [ 1 ]

Fix Version: 2.5 Beta 2 [ 10300 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @pcisar

status: Resolved [ 5 ] => Closed [ 6 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @pavel-zotov

QA Status: No test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants