Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix dtls multi-thread crash issue #1409

Merged
merged 4 commits into from
May 14, 2019

Conversation

yuanchao0310
Copy link
Contributor

@yuanchao0310
Copy link
Contributor Author

Sample code to reproduce the crash bug, it similar with the constructor of DtlsTransport.cpp (erizo/src/erizo/DtlsTransport.cpp)

#include "dtls/DtlsSocket.h"
#include <thread>

const int thread_num = 100;

void func() {
  boost::scoped_ptr<dtls::DtlsSocketContext> dtlsRtp;
  dtlsRtp.reset(new dtls::DtlsSocketContext());
  dtlsRtp->createClient();
}

int main()
{
  dtls::DtlsSocketContext::Init();
  std::thread th[thread_num];
  for (int i = 0; i < 100; i++ ) {
    for (int j = 0; j < thread_num; j++) {
      th[j] = std::thread(func);
    }
    for (int j = 0; j < thread_num; j++) {
      th[j].join();
    }
  }

  return 0;
}

the coredump backtrace looks like:
#0 0x0000000001af7c68 in rsa_pub_cmp ()
#1 0x0000000001a77d81 in X509_check_private_key ()
#2 0x00000000019fb793 in SSL_CTX_use_PrivateKey ()
#3 0x0000000000c0a06a in dtls::DtlsSocketContext::DtlsSocketContext (this=0x7fccccffe000) at /opt/download/licode/erizo/src/erizo/dtls/DtlsClient.cpp

@yuanchao0310
Copy link
Contributor Author

Another example code from ffmpeg:
https://github.com/FFmpeg/FFmpeg/blob/master/libavformat/tls_openssl.c

@jcague
Copy link
Contributor

jcague commented May 14, 2019

@yuanchao0310 I submitted a proposal with changes for this PR, including a unit test: yuanchao0310#1

Bugfix ssl multi threads (proposal to use std::thread and unit test)
@yuanchao0310
Copy link
Contributor Author

@yuanchao0310 I submitted a proposal with changes for this PR, including a unit test: yuanchao0310#1

Merged. Please review again.

Copy link
Contributor

@jcague jcague left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks a lot for this contribution @yuanchao0310 !

@jcague jcague merged commit 89c0d8e into lynckia:master May 14, 2019
Arri98 pushed a commit to Arri98/licode that referenced this pull request Apr 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants