Discussion:
[freetds] Memory problems with dbcmd
Alberto Pulvirenti
2012-12-04 09:45:40 UTC
Permalink
Dear all,

unfortunately, searching on google seemed to be unsuccessful for this, and
I didn't find any help looking ad previous discussions (maybe since I
subscribed this mailing list).

I have manage to set up a connection to a MS SQL database server using
freeTDS, but it sometimes (seldom, fortunately) happens that a dbcmd fails.
Looking at the various documentations, it should be a problem of memory
allocation, but this happened even for extremely simple queries like a
"begin transaction", and not always for the same query: it just happened in
a given moment, and it was not either possible to reproduce this problem,
but I remained afraid that it can appear again.
I don't really understand how can dbcmd fail with such a simple query when
the machine is not stuck (which I would think if it is a problem is so
serious that even such a small string cannot be allocated).

The MS SQL server stays in another machine to which I must connect through
network, although it is a machine internal to the location where all this
stuff runs. Can it happen that a sudden and momentary communication failure
causes dbcmd() to fail? Or its failure are only due to memory allocation
problems?

Is there any way I can adopt to deeper check this problem?

Thanks

Alberto
Frediano Ziglio
2012-12-04 19:30:58 UTC
Permalink
Post by Alberto Pulvirenti
Dear all,
unfortunately, searching on google seemed to be unsuccessful for this, and
I didn't find any help looking ad previous discussions (maybe since I
subscribed this mailing list).
I have manage to set up a connection to a MS SQL database server using
freeTDS, but it sometimes (seldom, fortunately) happens that a dbcmd fails.
Looking at the various documentations, it should be a problem of memory
allocation, but this happened even for extremely simple queries like a
"begin transaction", and not always for the same query: it just happened in
a given moment, and it was not either possible to reproduce this problem,
but I remained afraid that it can appear again.
I don't really understand how can dbcmd fail with such a simple query when
the machine is not stuck (which I would think if it is a problem is so
serious that even such a small string cannot be allocated).
The MS SQL server stays in another machine to which I must connect through
network, although it is a machine internal to the location where all this
stuff runs. Can it happen that a sudden and momentary communication failure
causes dbcmd() to fail? Or its failure are only due to memory allocation
problems?
Is there any way I can adopt to deeper check this problem?
Thanks
Alberto
Personally I would exclude a memory problem. If the system fails to
allocate few bytes of memory you should note other problems (unless
you set some limits on your program for instance using PHP module
which limit memory itself).

It's possible that connection got broken for some reason (a simple
service restart or a backup schedule which put database in some
particular state). Or even that server disconnect you cause you where
idle for too time (see recent keepalive discussion).

Frediano
Alberto Pulvirenti
2012-12-05 09:38:18 UTC
Permalink
Hi,

maybe I forgot to clarify a point. The failure I mention refers to the
function dbcmd().
I checked with a personal MS SQL Server I use for testing and I saw that
when the connection is faulty or the DB server is down, what happens is
that either the dbsqlsend() fails (and then I catch it) or the dbsqlok()
stays pending for a long time.
Whenever I try to switch off the server, it stops always there, never at
the dbcmd() level.

In all the documentations I see, when dbcmd fails it is always explained as
a memory problem, and it happens before one tries to send to the server
itself. That's what confused me.

It is surely possible that in a moment a memory occupancy spike took place
which caused this momentary failure (because, maybe I didn't stress this
point, but this failure was not a persistent condition, it happened just
once or twice and then the communication succeeded).

Thanks for any advice.

Alberto

2012/12/4 Frediano Ziglio <freddy77 at gmail.com>
Post by Alberto Pulvirenti
Post by Alberto Pulvirenti
Dear all,
unfortunately, searching on google seemed to be unsuccessful for this,
and
Post by Alberto Pulvirenti
I didn't find any help looking ad previous discussions (maybe since I
subscribed this mailing list).
I have manage to set up a connection to a MS SQL database server using
freeTDS, but it sometimes (seldom, fortunately) happens that a dbcmd
fails.
Post by Alberto Pulvirenti
Looking at the various documentations, it should be a problem of memory
allocation, but this happened even for extremely simple queries like a
"begin transaction", and not always for the same query: it just happened
in
Post by Alberto Pulvirenti
a given moment, and it was not either possible to reproduce this problem,
but I remained afraid that it can appear again.
I don't really understand how can dbcmd fail with such a simple query
when
Post by Alberto Pulvirenti
the machine is not stuck (which I would think if it is a problem is so
serious that even such a small string cannot be allocated).
The MS SQL server stays in another machine to which I must connect
through
Post by Alberto Pulvirenti
network, although it is a machine internal to the location where all this
stuff runs. Can it happen that a sudden and momentary communication
failure
Post by Alberto Pulvirenti
causes dbcmd() to fail? Or its failure are only due to memory allocation
problems?
Is there any way I can adopt to deeper check this problem?
Thanks
Alberto
Personally I would exclude a memory problem. If the system fails to
allocate few bytes of memory you should note other problems (unless
you set some limits on your program for instance using PHP module
which limit memory itself).
It's possible that connection got broken for some reason (a simple
service restart or a backup schedule which put database in some
particular state). Or even that server disconnect you cause you where
idle for too time (see recent keepalive discussion).
Frediano
_______________________________________________
FreeTDS mailing list
FreeTDS at lists.ibiblio.org
http://lists.ibiblio.org/mailman/listinfo/freetds
James K. Lowden
2012-12-08 17:24:01 UTC
Permalink
On Tue, 4 Dec 2012 10:45:40 +0100
Post by Alberto Pulvirenti
Can it happen that a sudden and momentary communication failure
causes dbcmd() to fail?
No.
Post by Alberto Pulvirenti
Or its failure are only due to memory allocation problems?
Also no! :-)

Have a look at the dbcmd() code in dblib.c. You'll note it can fail
for memory allocation reasons, but also checks the parameters it was
called with and the state of the connection first. The state of the
connection is *not* affected by transient network problems, though.
A connection's state is a function of how the most recent communication
with the server fared: as long as tcp doesn't report that the server
disconnected, and the client received a response (of any kind) from the
server for the previous query, the connection is considered OK. OTOH
if the server closed the connection, it is marked DEAD because no
further use can be made of it. A db-lib function invoked with a DEAD
dbproc fails immediately on seeing the DEAD status, saving pointless
lost time trying to use a connection that has no peer listening on the
other end.

dbcmd() invokes the error handler before it returns FAIL. Your
handler should display that message somewhere.

HTH.

--jkl

Loading...