Menu

#919 log: Race condition between timeout and reply

4.4.1
fixed
elunlen
None
defect
log
-
4.4.0
major
2014-05-26
2014-05-21
No

There is a race condition in lgs_file.c, where a reply can be sent by the file handling thread at the same time as the main thread times out waiting for the reply:

while (lgs_com_data.answer_f == false) {
    rc = pthread_cond_timedwait(
            &answer_cv, &lgs_ftcom_mutex, &timeout_time); /* -> UNLOCK -> LOCK */
    if (rc == ETIMEDOUT) {
        TRACE("Timed out before answer");
        api_rc = LGSF_TIMEOUT;
        lgs_com_data.timeout_f = true; /* Inform thread about timeout */
        goto api_exit;
    } else if (rc != 0) {
        TRACE("pthread wait Failed - %s",strerror(rc));
        osaf_abort(rc);
    }
}

When pthread_cond_timedwait() returns due a time-out in the code above, there is no check if the condition variable lgs_com_data.answer_f is true. The code should be changed to check (rc == ETIMEDOUT && lgs_com_data.answer_f == false), so that time-out handling is only performed when there is no reply.

Related

Tickets: #919
Wiki: ChangeLog-4.4.1

Discussion

  • elunlen

    elunlen - 2014-05-21
    • status: unassigned --> accepted
    • assigned_to: elunlen
     
  • elunlen

    elunlen - 2014-05-23
    • status: accepted --> review
     
  • elunlen

    elunlen - 2014-05-26
    • status: review --> fixed
     
  • elunlen

    elunlen - 2014-05-26

    changeset: 5319:bacc4f0b7548
    tag: tip
    parent: 5317:e12a2d0afdf7
    user: Lennart Lund lennart.lund@ericsson.com
    date: Mon May 26 13:49:32 2014 +0200
    summary: log: Fix possible thread race on timeout in file api [#919]

    rev: bacc4f0b75487cd79e4e2e76dabea0b83079f8dd

    changeset: 5318:edc1a29443bb
    branch: opensaf-4.4.x
    parent: 5316:cc06765dba2a
    user: Lennart Lund lennart.lund@ericsson.com
    date: Mon May 26 13:49:32 2014 +0200
    summary: log: Fix possible thread race on timeout in file api [#919]

    rev: edc1a29443bb43baf4d24bd61a337fad3862bede

     

    Related

    Tickets: #919


Log in to post a comment.