[Qt-interest] QTimer and crashing...
BRM
bm_witness at yahoo.com
Tue Aug 3 20:57:31 CEST 2010
The situation:
I have an application that reads data off of one TCP connection and then sends
out duplicate data to a series of others using signals and slots. Each network
connection is contained in its own dedicated thread (derived from QThread with
its own Event Loop), using signals and slots to communicate. The thread
interface only supports signals, and an internal class instance talks to the
network later (derived from QTcpSocket). Messages are only read off the network
when the whole message arrives. (All messages are small enough to not be a
problem for the TCP buffer sizes.)
I ran into a situation where some messages did not seem to get read off the
network. So I added a QTimer. The timer is started (250-1000 ms) when after the
data is read off the network and it is determined there is nothing left to read
but there is still some data for reading - e.g. a partial message is in the
buffer. Upon receiving the readyRead signal, the QTimer is stopped, and then it
processes the network data. (Before the loop is a second stop for the QTimer.)
For the most part this works without a problem. I mostly employed this tactic
due to how readyRead[1] is emitted.
The problem:
While I employ the above on every QTcpSocket derived interface, one or two
interfaces in-particular seem to be causing an occasional crash of the software.
While other software employs this same tactic, it only _seems_ to be affecting
this one program.This may take a short program run (e.g. ~30 minutes) or a long
run (e.g. 120 minutes) to occur. When it does occur, the crash seems to always
happen on the first QTimer::stop() call. Sometimes gdb catches it in a different
thread, but there is always a thread that is in that call. More specifically,
the QTimer has called killTimer(), which is down managing its lists of timers to
remove the timer from the list - crashing on a memmove().
I've been tracing the program for a few days already, trying to figure out why
it is crashing. On one instance (and only one instance out of dozens of crashes)
GDB reported a memory corruption error. I have had a hard time finding that it
is is really the QTimer that is the problem; but a rebuild and test with that
disabled in the interfaces in question seems to be producing a working version
that is not crashing. At the data rate I am pushing through, the timer should
not actually be going off as I should be receiving data long before it times out
- basically data comes at 240-400 HZ depending on configuration. I did try
looking through the bug database on-line, but didn't see anything that seemed
relevant.
FYI - this is all under Linux 2.6.24-28-generic (kubuntu 8.04 TLS with updates)
Qt 4.5.1 with gcc/g++ 4.2.4. (Just haven't upgraded to 4.6 yet due to time
requirements.)
Am I doing something wrong? Or should I be filing a bug with Nokia/Qt?
TIA,
Ben
[1] http://doc.trolltech.com/4.5/qiodevice.html#readyRead
More information about the Qt-interest-old
mailing list