[Solved] What are the odds that a QTimer or an event loop is being stopped?


  • Moderators

    I have an application which shall run basically 24/7. It has a timer firing every 5 seconds for some activity. This activity includes some screen output.

    The application is establishing TCP/IP connection to somewhere outside. Eventually these connection break down and have to be reconnected.

    The application is not new and some problems I had seen before. However, it was merely after a week or weeks. Now I am running more TCP sockets in parallel and the problem is actually coming within half a day. And it is showing messages of reconnection for those TCP/IP socket.

    However, I do see a reason why the timer is not triggered anymore.

    Any suggestions?



  • Hi,
    Without code it's almost impossible to help, but still a Timer will never stop working. Are you sure you don't kill/hang your eventLoop Handler? Do you reinitialize your timer in a slot?
    What type of timer do you use? Just a normal Timer that runs and runs and expires every 5 secs or do you use a SingleShot timer?
    In what tread do you run your TCP/IP connections? Is that thread still running? When it's in the Mainthread and your GUI hangs (e.g. a warning message with modal view) the events of all other objects is stalled.
    But again, without code, no idea what could go wrong!


  • Moderators

    @Jeroentjehome

    Thanks for reply. You are right that without code it is always a problem. However, the code would be too complex to comprehend.

    Sometimes it is helpful to describe that someone else can get an idea what you are doing. Even "general" answers may provide the spark for better grabbig the problem.

    @Jeroentjehome said:

    Without code it's almost impossible to help, but still a Timer will never stop working.

    That reflects my understanding.

    Are you sure you don't kill/hang your eventLoop Handler? Do you reinitialize your timer in a slot?

    Nope.

    What type of timer do you use? Just a normal Timer that runs and runs and expires every 5 secs or do you use a SingleShot timer?

    QTimer and it runs continuously, at least it should.

    In what tread do you run your TCP/IP connections? Is that thread still running? When it's in the Mainthread and your GUI hangs (e.g. a warning message with modal view) the events of all other objects is stalled.

    Only the main thread. no additional explicit threading done.

    I have checked for a "wild" loop, but the task manager does not show CPU consumption. It looks idle to me. I guess all connection are stopped in the mean time. The timer loop shall actually ensure that those connections are re-established.
    I am using waitforconnection() for TCP socket, but I limit those to 30 seconds.


  • Lifetime Qt Champion

    Hi,

    What OS are you running ?

    Are you re-using the same sockets or creating new ones ?


  • Moderators

    @SGaist
    OS is windows 7 64 bit. Qt 5.3.1 MinGW 32 bit to be precise.
    I see aparently the same issue on Windows 2008 server editions.

    When I decide that a socket has to be reconnected because no info is coming in, I am deleting this socket and set up a new one.
    This is a direct delete in the wrapper. Since no crashes are occurring it seems to be possible. So there is no deleteLater and an overlap for whatever reason.



  • Using deleteLater would be better if you use connections to the deleted socket. That will make sure your event queue is empty.
    Are there delays in your socket setup? Do you restart the timer there or do you just keep on going? Do you wait for a system response when you delete or start a socket?
    Does your GUI still run when your program halts?


  • Moderators

    @Jeroentjehome
    I have one main timer which is not restarted, but not stopped either. This timer is triggering the screen output. That is also the timer in question, because at a certain point is not fired anymore.

    Basically each QTcpSocket is hosted in a class which hjas independent QTimer as a watch dog. Those timers are not restarted.

    Sometimes there are socket delays. At least that is my assumption since there are several starts in a row.

    The application in question does not have a GUI. However, I am using the same stuff in an application with GUI. The GUI eventually blocks and no way to get it back. Assume that I am looking for the same issue here.

    I have noted this morning that the main timer, which shall be fired every 5 seconds, is varying quite a lot. Have seen values between 1 up to 20 seconds. The event loop must busy for something, respectively it is waiting for something.

    The QTcpSocket is an instance in my wrapper class. The direct delete kills the socket and all connections at once. There should be no additional signals coming in and messing up the decoding I am doing. As indicated above, the delete does not crash anything, which is to be expected since the pointer is not owned in one of the other classes.


  • Lifetime Qt Champion

    What OS is it ?

    Do you have a WiFi adapter on the machine ?


  • Moderators

    @SGaist
    OS is win 7 64 bit primarily.
    No WIFI used.

    I have changed the code yesterday. I found, actually I knew its presence, a waitForReadyRead(-1) in the code, when I requested more bytes to read than actually available. Certainly that would explain immediately the behaviour. However, this was only possible to enter when the number of bytesAvailable() would report the wrong number of bytes. I doubt that bytesAvailable would report more bytes than actually available. Anyway I took away those odds.


  • Moderators

    I have found the problem. It was a blocking ftp download which did not finish because of broken communication. Pushing the download to a separate thread unveiled the problem respectively made it tracable.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.