uNetworking / uWebSockets

Simple, secure & standards compliant web server for the most demanding of applications
Apache License 2.0
17.24k stars 1.75k forks source link

Segmentation fault when returning SSL_CTX of the app #1756

Open ShakyaPr opened 3 months ago

ShakyaPr commented 3 months ago

Description:

I am experiencing a segmentation fault when attempting to retrieve the SSL context of my SSL server using the following code: SSL_CTX* sslContext = static_cast<SSL_CTX *>(_ssl_server->getNativeHandle());

Observations:

  1. Stack Trace : I used gdb to obtain the stack trace, which points to an issue in openssl.c: image

  2. Library Build : The uWebSocket library was built without the LIBUS_NO_SSL flag.

  3. Comparative Test : To isolate the issue, I created an identical HTTPS server in a separate project. In this test project, I was able to retrieve the SSL_CTX without any issues. Both projects use the same libraries and versions, but only my current development project encounters the segmentation fault.

Details:

Current Development Environment:

Test Project Environment:

  1. Why is there a difference in behavior between the two projects?
  2. The stack trace indicates a reference to openssl.c, which is not visited in the working test project. What could be causing this discrepancy?
  3. Are there any known issues or additional configurations needed when using uWebSockets with SSL in a specific project setup?
uNetworkingAB commented 3 months ago

Like always, AddressSanitizer is your friend

uNetworkingAB commented 3 months ago

Context is nullptr, why? I don't know

ShakyaPr commented 3 months ago

We are running three server instances in three different threads. Occasionally, when creating an ssl_server object using SSLApp, the httpContext is null. Is there any reason for this? Is this socket creation isn't thread safe?

uNetworkingAB commented 2 months ago

Like always, AddressSanitizer is your friend

Use these tools. If you wonder about threading, use ThreadSanitizer. I don't accept bug reports of crashes without these tools being used.