[MXS-3023] worker id overflow Created: 2020-06-04  Updated: 2020-06-05  Resolved: 2020-06-05

Status: Closed
Project: MariaDB MaxScale
Component/s: Core
Affects Version/s: 2.3.19
Fix Version/s: 2.3.21, 2.4.10

Type: Bug Priority: Minor
Reporter: danielforever Assignee: markus makela
Resolution: Fixed Votes: 0
Labels: None


 Description   

RoutingWorker* RoutingWorker::pick_worker()
{
    static int id_generator = 0;
    int id = this_unit.id_min_worker
        + (mxb::atomic::add(&id_generator, 1, mxb::atomic::RELAXED) % this_unit.nWorkers);
    return get(id);
}

In code above, id_generator is int, when it overflows, it becomes negative integer, then we will have an invalid worker_id in 2.2.

in 2.3, it's different, but `get(id)` will return nullptr, this requires the calling method to check if worker is empty. Apparently, gw_process_one_new_client is not doing it:

1487     mxs::RoutingWorker* worker = mxs::RoutingWorker::pick_worker();
1488
1489     worker->execute([=]() {

suggested fix:

change id_generator to unsigned type



 Comments   
Comment by danielforever [ 2020-06-04 ]

Besides, some fields of statistics (server, session etc) have the same problem

Generated at Thu Feb 08 04:18:24 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.