On 17/09/2025 13:25, Stefan Schmaltz wrote:
> Looks like a test case is not providable. Running search in AWT-
> Eventqueue, executing query in separate thread.
>
> But I found a solution:
>
> stmt.cancel();
> if (stmt instanceof FBStatement fbstmt)
> {
> FbDatabase fbDatabase = fbstmt.getConnection().getFbDatabase();
> if (fbDatabase instanceof AbstractFbWireDatabase wireDb)
> try
> {
> wireDb.getXdrStreamAccess().getXdrIn().close();
> }
> catch (IOException | SQLException e)
> {
> e.printStackTrace();
> }
> }
>
> Maybe add this to your cancel() code?
That will terminate the entire connection, not just cancel the statement.
I'll see if I can find the problem or make it somehow reproducible.
There are two possibilities I can think of:
1) as I said the cancellation is not entirely thread-safe, because
making it entirely thread-safe would require using separate
(overlapping) locks for sending and receiving data. Maybe the send of
the cancellation happened in the middle of sending other data (though
the fact server-side the cancellation was handled seems to exclude that).
2) The hang happens when processing deferred operations, maybe one of
the deferred operations wasn't properly removed from the queue when
cancellation was received, or I missed an operation that would also be
affected by cancellation.
However, based on your description, you may want to consider - as a
workaround at least - to accumulate user input for at least X
milliseconds before cancelling the previous statement. As long as the
user adds characters (i.e. the previous search is the prefix of the next
search), you could even consider waiting for the query result and
post-process and filter it locally (or even filter a previously received
result locally).
I've created
https://github.com/FirebirdSQL/jaybird/issues/892 to
investigate and hopefully fix this.
Mark
--
Mark Rotteveel