QTimer handle leak from inside Qt?
-
Hi. The software I'm working on (using Qt 5.5) crashed recently and I cannot figure out why. The latest log output suggested the event loop was under a lot of stress but running.
The error message from the main thread "QEventDispatcherWin32::registerTimer: Failed to create a timer (The current process has used all of its system allowance of handles for Window Manager objects.)" is printed every 500usec to the log handler. It is unknown where it began, I cannot reproduce it or know how it started.
The user after about 20 minutes called abort on the Windows message "window is not responding".
Something has begun leaking handles while creating timer object probably as fast as possible (the 500usec delta is probably the slowdown due to the error message log handler call). I examined every "new QTimer" and every "QTimer::singleShot" in the source code: nowhere is this created in a loop, in a recursion or in code called repeatedly like this.
This is probably a though guess but are there any qt constructs which implicitly create QTimer object / handles which might help identify what's get called here?
I first suggested this might be for some reason too many C++11 calls to QThreadLoop using QtConcurrent::run ...but only handles with the maximum amount of active worker threads are actually consumed.
Any insight on what might be wrong here? Thank you!
-
Hi. The software I'm working on (using Qt 5.5) crashed recently and I cannot figure out why. The latest log output suggested the event loop was under a lot of stress but running.
The error message from the main thread "QEventDispatcherWin32::registerTimer: Failed to create a timer (The current process has used all of its system allowance of handles for Window Manager objects.)" is printed every 500usec to the log handler. It is unknown where it began, I cannot reproduce it or know how it started.
The user after about 20 minutes called abort on the Windows message "window is not responding".
Something has begun leaking handles while creating timer object probably as fast as possible (the 500usec delta is probably the slowdown due to the error message log handler call). I examined every "new QTimer" and every "QTimer::singleShot" in the source code: nowhere is this created in a loop, in a recursion or in code called repeatedly like this.
This is probably a though guess but are there any qt constructs which implicitly create QTimer object / handles which might help identify what's get called here?
I first suggested this might be for some reason too many C++11 calls to QThreadLoop using QtConcurrent::run ...but only handles with the maximum amount of active worker threads are actually consumed.
Any insight on what might be wrong here? Thank you!
Hi and welcome to devnet forum
This is merely a user's forum. Your question is probably better suited in the developer's mailing list.
Also your Qt version is fairly old. Can't you update to more recent versions? We have already version 5.12.
-
Hi. The software I'm working on (using Qt 5.5) crashed recently and I cannot figure out why. The latest log output suggested the event loop was under a lot of stress but running.
The error message from the main thread "QEventDispatcherWin32::registerTimer: Failed to create a timer (The current process has used all of its system allowance of handles for Window Manager objects.)" is printed every 500usec to the log handler. It is unknown where it began, I cannot reproduce it or know how it started.
The user after about 20 minutes called abort on the Windows message "window is not responding".
Something has begun leaking handles while creating timer object probably as fast as possible (the 500usec delta is probably the slowdown due to the error message log handler call). I examined every "new QTimer" and every "QTimer::singleShot" in the source code: nowhere is this created in a loop, in a recursion or in code called repeatedly like this.
This is probably a though guess but are there any qt constructs which implicitly create QTimer object / handles which might help identify what's get called here?
I first suggested this might be for some reason too many C++11 calls to QThreadLoop using QtConcurrent::run ...but only handles with the maximum amount of active worker threads are actually consumed.
Any insight on what might be wrong here? Thank you!
@magnus.ni
There seem to be two possibilities:-
Despite what you say, your code is somehow creating many timers (e.g. via slots). Are you freeing the
QTimers when you're done with them? If you are only usingQTimer::singleShot, do you need those instances, could you just use the static version? -
As e.g. @SGaist said in https://forum.qt.io/topic/54438/solved-qt-5-4-1-qtimer-using-up-all-handles-for-window-manager-objects, it may not be the
QTimeritself which is being repeatedly created. The error message could just indicate that you are using up too many Windows handles in general, e.g. from widgets or whatever else in your code. (In that link it turned out the OP was creating multipleQNetworkAccessManagers --- not saying that's you, but could be anything.)
-
-
If the process is running you can get the details of handles which are open. Either use process explorer or sone other tool to see the handle details. It is possible that timer error just a manifestation of some other issue.
-
Hi and welcome to devnet forum
This is merely a user's forum. Your question is probably better suited in the developer's mailing list.
Also your Qt version is fairly old. Can't you update to more recent versions? We have already version 5.12.
@koahnig said in QTimer handle leak from inside Qt?:
Hi and welcome to devnet forum
This is merely a user's forum. Your question is probably better suited in the developer's mailing list.
Also your Qt version is fairly old. Can't you update to more recent versions? We have already version 5.12.
Thank you very much. I'm afraid this won't be possible. Maybe we can switch to 5.6 in the nearest future (since we're stuck to msvc2010 and 5.6 is the latest build supporting it)
@dheerendra said in QTimer handle leak from inside Qt?:
If the process is running you can get the details of handles which are open. Either use process explorer or sone other tool to see the handle details. It is possible that timer error just a manifestation of some other issue.
Thank you. This might be possible. But I myself cannot reproduce the issue or have seen it live.
-
@magnus.ni
There seem to be two possibilities:-
Despite what you say, your code is somehow creating many timers (e.g. via slots). Are you freeing the
QTimers when you're done with them? If you are only usingQTimer::singleShot, do you need those instances, could you just use the static version? -
As e.g. @SGaist said in https://forum.qt.io/topic/54438/solved-qt-5-4-1-qtimer-using-up-all-handles-for-window-manager-objects, it may not be the
QTimeritself which is being repeatedly created. The error message could just indicate that you are using up too many Windows handles in general, e.g. from widgets or whatever else in your code. (In that link it turned out the OP was creating multipleQNetworkAccessManagers --- not saying that's you, but could be anything.)
Thank you!
@JonB said in QTimer handle leak from inside Qt?:
@magnus.ni
There seem to be two possibilities:- Despite what you say, your code is somehow creating many timers (e.g. via slots). Are you freeing the
QTimers when you're done with them? If you are only usingQTimer::singleShot, do you need those instances, could you just use the static version?
I'm very seldom explicitly create timers on the heap and almost any of those are single members of a class and bound to the lifetime of the owning class.
I didn't find any ownership problems or recursive slot mechanisms here. When I need single shot I almost always use the static version.- As e.g. @SGaist said in https://forum.qt.io/topic/54438/solved-qt-5-4-1-qtimer-using-up-all-handles-for-window-manager-objects, it may not be the
QTimeritself which is being repeatedly created. The error message could just indicate that you are using up too many Windows handles in general, e.g. from widgets or whatever else in your code. (In that link it turned out the OP was creating multipleQNetworkAccessManagers --- not saying that's you, but could be anything.)
I've read the thread but didn't use the
QNetworkAccessManageror something familiar. I've seached the large codebase for any obviousQTimermisusages but without being able to reproduce the issue. But any idea why this might have implicitly occurred are most welcome since I already watched any QTimer construction in the code for possible side effects like this.Thank you very much
-