Skip to content
New issue

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

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

Already on GitHub? # to your account

Fix for sigabort's due to (rare) AMD incompatibility with std::random_device #6

Open
TheOnlyJoey opened this issue Nov 7, 2023 · 0 comments

Comments

@TheOnlyJoey
Copy link

TheOnlyJoey commented Nov 7, 2023

It seems that there are problems with some systems (mostly more modern AMD systems) where in some cases std::random_device will result in an exception. Currently this causes applications to be unusable.

Referencing this issue in libsass, I made a quick patch for solving this problem.

Since the current state of branches seems to be undergoing some refactoring/updating to newer version, and i have no idea where to PR to at this point, here is a diff based on the sonobus main repo.

Sonobus works as expected using this patch, where before it would crash on start.

diff --git a/deps/aoo/lib/src/client.cpp b/deps/aoo/lib/src/client.cpp
index f02e5ce6..0ec74259 100644
--- a/deps/aoo/lib/src/client.cpp
+++ b/deps/aoo/lib/src/client.cpp
@@ -170,11 +170,16 @@ aoo::net::client::client(void *udpsocket, aoo_sendfn fn, int port)
     sendbuffer_.setup(65536);
     recvbuffer_.setup(65536);
     
-    // generate random token
-    std::random_device randdev;
-    std::default_random_engine reng(randdev());
-    std::uniform_int_distribution<int64_t> uniform_dist(1); // minimum of 1, max of maxint
-    token_ = uniform_dist(reng);
+    try {
+        std::random_device randdev;
+        std::default_random_engine reng(randdev());
+        std::uniform_int_distribution<int64_t> uniform_dist(1); // minimum of 1, max of maxint
+        token_ = uniform_dist(reng);
+    }
+    // On certain system this can throw since either
+    // underlying hardware or software can be buggy.
+    // https://github.com/sass/libsass/issues/3151
+    catch (std::exception&) {}
 }
 
 void aoonet_client_free(aoonet_client *client){
diff --git a/deps/aoo/lib/src/source.cpp b/deps/aoo/lib/src/source.cpp
index 82f02088..c769d0f2 100644
--- a/deps/aoo/lib/src/source.cpp
+++ b/deps/aoo/lib/src/source.cpp
@@ -899,10 +899,18 @@ int32_t source::set_format(aoo_format &f){
 }
 
 int32_t source::make_salt(){
-    thread_local std::random_device dev;
-    thread_local std::mt19937 mt(dev());
-    std::uniform_int_distribution<int32_t> dist;
-    return dist(mt);
+    try {
+      thread_local std::random_device dev;
+      thread_local std::mt19937 mt(dev());
+      std::uniform_int_distribution<int32_t> dist;
+      return dist(mt);
+
+    }
+    // On certain system this can throw since either
+    // underlying hardware or software can be buggy.
+    // https://github.com/sass/libsass/issues/3151
+    catch (std::exception&) {}
+    return 42;
 }
 
 int32_t source::set_userformat(void * ptr, int32_t size){
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant