Bug #79782 implement retry logic for event scheduler in case it cannot create a new thread
Submitted: 28 Dec 2015 5:57
Reporter: Shane Bester (Platinum Quality Contributor) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Stored Routines Severity:S4 (Feature request)
Version:5.6.28 OS:Any
Assigned to: CPU Architecture:Any

[28 Dec 2015 5:57] Shane Bester
Description:
At times the event scheduler disables itself like this:

[Note] Event Scheduler: scheduler thread started with id 4
[ERROR] Event_scheduler::execute_top: Can not create event worker thread (errno=11). Stopping event scheduler

How to repeat:
no exact testcase.

Suggested fix:
This is a request to retry creating the worker threads until it succeeds.
Please log every retry and error code.
[28 Dec 2015 5:58] MySQL Verification Team
existing code looks like this:

  /*
    TODO: should use thread pool here, preferably with an upper limit
    on number of threads: if too many events are scheduled for the
    same time, starting all of them at once won't help them run truly
    in parallel (because of the great amount of synchronization), so
    we may as well execute them in sequence, keeping concurrency at a
    reasonable level.
  */
  /* Major failure */
  if ((res= mysql_thread_create(key_thread_event_worker,
                                &th, &connection_attrib, event_worker_thread,
                                event_name)))
  {
    mysql_mutex_lock(&LOCK_global_system_variables);
    Events::opt_event_scheduler= Events::EVENTS_OFF;
    mysql_mutex_unlock(&LOCK_global_system_variables);

    sql_print_error("Event_scheduler::execute_top: Can not create event worker"
                    " thread (errno=%d). Stopping event scheduler", res);

    new_thd->proc_info= "Clearing";
    DBUG_ASSERT(new_thd->net.buff != 0);
    net_end(&new_thd->net);

    goto error;
  }
[28 Dec 2015 7:13] MySQL Verification Team
Or, as the comment hints, pre-create some threads in case system limits are getting hit and no new threads can be created on demand.
[8 Sep 2016 9:09] MySQL Verification Team
the errors in the description were added with this commit:
https://github.com/mysql/mysql-server/commit/f757293bc8bb49e83c3a65125dd90282cbda397c