Skip to content

100% cpu usage in winthreads tor_cond_wait

For years I run relay using self-compiled win64 version of tor. Compiler mingw64. Relay runs well for some time but suddenly starts using 100% cpu all cores. I traced where it happens. The following loop never ends :


  do {
    DWORD res;
    res = WaitForSingleObject(cond->event, ms);
    EnterCriticalSection(&cond->lock);
    if (cond->n_to_wake &&
        cond->generation != generation_at_start) {
      --cond->n_to_wake;
      --cond->n_waiting;
      result = 0;
      waiting = 0;
      goto out;
    } else if (res != WAIT_OBJECT_0) {
      result = (res==WAIT_TIMEOUT) ? 1 : -1;
      --cond->n_waiting;
      waiting = 0;
      goto out;
    } else if (ms != INFINITE) {
      endTime = GetTickCount();
      if (startTime + ms_orig <= endTime) {
        result = 1; /* Timeout */
        --cond->n_waiting;
        waiting = 0;
        goto out;
      } else {
        ms = startTime + ms_orig - endTime;
      }
    }
    /* If we make it here, we are still waiting. */
    if (cond->n_to_wake == 0) {
      /* There is nobody else who should wake up; reset
       * the event. */
      ResetEvent(cond->event);
    }
  out:
    LeaveCriticalSection(&cond->lock);
  } while (waiting);

res = WAIT_OBJECT_0; ms = INFINITE; cond->n_to_wake=0x11 cond->generation=0x28 generation_at_start=0x28

it means no path with "goto out" ever execute more than one thread run this loop and each one eat separate core

Some people I shared binaries with report same problem. Pls check

Trac:
Username: bolvan

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information