drachtio-freeswitch-modules icon indicating copy to clipboard operation
drachtio-freeswitch-modules copied to clipboard

mod_audio_fork - clearing pending connections

Open hhadzem opened this issue 2 years ago • 4 comments

Hi Dave,

As it seems like, clearing pending connections does not work properly if the specified websocket is not valid.

AudioPipe* AudioPipe::findAndRemovePendingConnect(struct lws *wsi) {
  AudioPipe* ap = NULL;
  std::lock_guard<std::mutex> guard(mutex_connects);

  for (auto it = pendingConnects.begin(); it != pendingConnects.end() && !ap; ++it) {
    int state = (*it)->m_state;
    if ((state == LWS_CLIENT_CONNECTING) &&
      (*it)->m_wsi == wsi) ap = *it;
  }

  if (ap) {
    pendingConnects.remove(ap);
  }

  return ap;
}

The check given here (*it)->m_wsi == wsi is never true if the following line in processPendingConnects does not resolve websocket properly: ap->connect_client(vhd);. More specifically, m_wsi = lws_client_connect_via_info(&i); will result in m_wsi being nullptr and will never equal to wsi parameter passed to lws_callback.

Can you confirm this is the expected behaviour and not a mistake on my behalf? Thanks in advance.

hhadzem avatar Sep 03 '22 12:09 hhadzem

Hmm, I think you may be correct. It will be a few days or so before I can look further into it. If you have a solution, please post a PR. Thanks!

davehorton avatar Sep 05 '22 12:09 davehorton

Thanks for the answer. I'll propose a solution (that you might find to be more of a hack, than a solution, but it does remove faulty connect gracefully), and post a PR.

hhadzem avatar Sep 05 '22 13:09 hhadzem

why did you close the issue?

davehorton avatar Sep 06 '22 19:09 davehorton

why did you close the issue?

Must have accidentally closed it. Sorry for inconvenience.

hhadzem avatar Sep 06 '22 19:09 hhadzem