Glimesh / janus-ftl-plugin

A plugin for the Janus WebRTC gateway to enable relaying of audio/video streams utilizing Mixer's FTL (Faster-Than-Light) protocol.
https://hayden.fyi/posts/2020-08-03-Faster-Than-Light-protocol-engineering-notes.html
GNU Affero General Public License v3.0
44 stars 11 forks source link

❣️ Fix use-after-free bug from using httplib::Client in non-thread-safe ways #100

Closed danstiner closed 3 years ago

danstiner commented 3 years ago

We've been seeing some strange crashes that looked like memory corruption.

After some hunting around we think we've narrowed it down to using the class instance of httplib::Client from multiple threads in parallel.

Technically the client does have a request mutex, but that has two limitations:

  1. Changing headers is not protected by the request mutex, we think this is leading to the memory corruption.
  2. Only one request may be in-flight at a time with a single client, this is probably adding significant latency in some cases

The downside of this is that we establish a new connection for basically every request, but I think the latency that can add is minimal compared to the above downsides.

Verified the GlimeshServiceConnection still works using my homelab setup.