drachtio / drachtio-freeswitch-modules

A collection of open-sourced freeswitch modules that I use in various drachtio applications
MIT License
171 stars 119 forks source link

mod_audio_fork - clearing pending connections #89

Open hhadzem opened 2 years ago

hhadzem commented 2 years ago

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.

davehorton commented 2 years ago

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!

hhadzem commented 2 years ago

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.

davehorton commented 2 years ago

why did you close the issue?

hhadzem commented 2 years ago

why did you close the issue?

Must have accidentally closed it. Sorry for inconvenience.