Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential Data Race in HeartbeatClient #1

Open
viennadd opened this issue Jul 28, 2017 · 1 comment
Open

Potential Data Race in HeartbeatClient #1

viennadd opened this issue Jul 28, 2017 · 1 comment

Comments

@viennadd
Copy link

viennadd commented Jul 28, 2017

Hi,

Our code scanner has reported a data race at workLoop method of HeartbeatClient

bool HeartbeatClient::start() {
    int err = pthread_create(&_thread, NULL, &HeartbeatClient::workLoop, this);
    if (err != 0) {
        LOG(ERROR) << "Cannot start thread for heartbeat client";
        return false;
    }
    _running = true;
    LOG(INFO) << "Start sending heartbeats to '" << _remoteHost << ":" << _remotePort << "'";
    return true;
}

_running initialized with false,
Could there is a chance that HeartbeatClient::workLoop access the _running before the main thread has assigned true into, the heart beat thread might just stopped before the main thread has updated the value of _running.

May be we could move the assignment into thread body to avoid this issue.

void* HeartbeatClient::workLoop(void *arg) {
   ......
    // client->_running = true;                 // <======    move here instead 
    while (client->_running) {

Regards,
Alex, SourceBrella Inc.

@richardxx
Copy link

Anybody please have a look, your feedback can encourage us to contribute more to improving open source quality, :>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants