If both data channels become ready simultaneously, then the two integer read-add-update cycles can execute concurrently and only ever increment once instead of the required twice. Use an atomic add instead.
Mostly follows the W3C specification https://www.w3.org/TR/webrtc/#peer-to-peer-data-api With contributions from: Mathieu Duponchelle <mathieu@centricular.com> https://bugzilla.gnome.org/show_bug.cgi?id=794351