ct_cancel() issue

Andrew Victor <[email protected]>
Newsgroups gmane.comp.db.tds.freetds
Message-ID <CAFumwP3uJUx6SSfE26DLViEKMCSgSYb0ZCKQ1P+XaA=iG307bQ@mail.gmail.com>
hi,

I'm busy updating an application from FreeTDS 0.82 to the latest
(0.91.96), and am running into an issue a change to the ct_cancel()
function.

The application is a long-running daemon that makes use of a
connection-pool of persistent connections to a MS-SQL server.  Before
returning a connection back to the pool a ct_cancel(CS_CANCEL_ALL) is
issued to ensure that incomplete commands are terminated, and any
unread result-sets discarded - ie, the server and connection are in a
"known" state.

With FreeTDS 0.91.96, the ct_cancel() call returns but the
"cancel_state" remains in _CS_CANCEL_PENDING state:

      tds_send_cancel(conn->tds_socket);
      tds_process_cancel(conn->tds_socket);
       _ct_initialise_cmd(conn_cmd);
       conn_cmd->cancel_state = _CS_CANCEL_PENDING;


Note: the other types of cs_cancel() don't call tds_process_cancel().


When the connection is later re-used from the pool, the subsequent
calls to ct_send() fails due to this code:

    if (cmd->cancel_state == _CS_CANCEL_PENDING) {
        _ct_cancel_cleanup(cmd);
        return CS_CANCELED;
    }

and _ct_cancel_cleanup() basically just calls:

   tds_process_cancel(con->tds_socket);


Therefore tds_process_cancel() gets called twice, and the
"cancel_state" stays in _CS_CANCEL_PENDING state.


The change seems related to this post on the mailing-list:
   http://lists.ibiblio.org/pipermail/freetds/2008q2/023233.html
and this commit:
   https://gitorious.org/freetds/freetds/commit/96a34d413e02095a4c9c90a6a3936bd57f4d6073


Commenting the two lines:
    conn_cmd->cancel_state = _CS_CANCEL_PENDING;
seems to solve the issue.

I did also try the latest git version.


Regards,
  Andrew Victor
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.