Skip to Content.
Sympa Menu

freetds - [freetds] [PATCH] Bugfix for cancelling a query

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Alex Kiesel <alex.kiesel AT document-root.de>
  • To: freetds AT lists.ibiblio.org
  • Subject: [freetds] [PATCH] Bugfix for cancelling a query
  • Date: Sun, 11 Jan 2004 00:55:37 +0100

Hi again,

attached is another patch which fixes freetds' behaviour when cancelling
a query. At the moment, when cancelling a query, a cancel packet is
being sent (that is, an empty packet with the headers out_flag set to
0x06 = attention packet). After this, all packets are read until an
acknowledgement of the cancel has been received.

Now, the wire does not contain more data - but as the cancel has been
sent asynchroneously, a client can (and e.g. sqsh often does) call one
of ct_results, ct_fetch and probably more. Thus, this all comes down to
goodread(); freetds tries to read data from the wire where there is no
data available. Due to the timeout handling code - this is being done
over and over again.

My patch changes this to return 0 when the socket is not ready for read
operations. This lets the client leave the result-handling code and
return to "normal" operation. It can start a new query.

After applying this patch, all ctlib- and tds-unittests succeed.
dblib-tests t0013 and t0014 fail; this is a pure timeout problem.
Setting the sockets read timeout to something higher than 1 second fixes
both tests - and all tests pass. I have not enough knowledge to judge
whether this is critical for dblib.

Could someone have a look at this? It would be great if this could be
included into 0.62 if the unittests can be fixed by someone...

Greets,
-Alex
Index: src/tds/read.c
===================================================================
RCS file: /home/cvs/mirror/freetds/freetds/src/tds/read.c,v
retrieving revision 1.78
diff -u -r1.78 read.c
--- src/tds/read.c	29 Dec 2003 16:08:35 -0000	1.78
+++ src/tds/read.c	10 Jan 2004 23:53:21 -0000
@@ -164,6 +164,13 @@
 			buflen -= len;
 			got += len;
 		} 
+
+		/* When we get a timeout on select(), return 0. Don't return -1, because
+		 * that would lead to a disconnect 
+		 * OTOH, do not let this pass to prevent an infinite loop when there is
+		 * no data on the wire */
+		if (retcode == 0)
+			return 0;
 		
 		OK_TIMEOUT:
 		now = time(NULL);



Archive powered by MHonArc 2.6.24.

Top of Page