Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo


#112 TaskManager::_taskList contains tasks that never started

Dave Shawley

I think that there is a bug in Poco::TaskManager::start that causes _taskList to contain a task that isn't running... more correctly, it never started. The code was pushing the task onto _taskList before it was started in the thread pool. If the pool couldn't allocate the thread due to its configuration (maxThreads) or some other failure, then it will throw an exception and the Task object stays on the _taskList. Since the task never starts, it follows that it never finishes cleanly either. The only place that a Task object is ever removed from _taskList is in the taskFinished callback so any Task object that cannot be run on a thread is stranded on _taskList.

The patch is pretty simple - just add a try-catch block and pop _taskList if an exception is thrown:

--- src/TaskManager.cpp (revision 391)
+++ src/TaskManager.cpp (working copy)
@@ -64,12 +64,24 @@

void TaskManager::start(Task* pTask)
+ TaskPtr pAutoTask(pTask); // take ownership immediately
FastMutex::ScopedLock lock(_mutex);

  • pTask->setOwner(this);
  • pTask->setState(Task::TASK_STARTING);
  • _taskList.push_back(TaskPtr(pTask));
  • _threadPool.start(*pTask, pTask->name());
  • pAutoTask->setOwner(this);
  • pAutoTask->setState(Task::TASK_STARTING);
  • _taskList.push_back(pAutoTask);
  • try
  • {
  • _threadPool.start(*pAutoTask, pAutoTask->name());
  • }
  • catch (...)
  • {
  • // Make sure that we don't act like we own the task since
  • // we never started it. If we leave the task on our task
  • // list, the size of the list is incorrect.
  • _taskList.pop_back();
  • throw;
  • }

Should I commit this to trunk or create a copy in sandbox and commit it? I also added a new test case to TaskManagerTest.cpp to verify the fix.


  • Dave Shawley
    Dave Shawley

    Logged In: YES
    Originator: YES

    Fixed in SVN Revision 397

  • Logged In: YES
    Originator: NO

    fixed in 1.3.2