Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rack error - RuntimeError: failed to get urandom in a Rails app (Rails 5.0.6, Ruby 2.5.5)

I'm making a lot of API requests to a Rails 5.0(.6) app running locally. It inconsistently fails with the Rack error: RuntimeError: failed to get urandom

The backtrace is to the SecureRandom module, not in the application (specifically the uuid method). From there it is in ActionDispatch::RequestId. Unfortunately, the full backtrace is gone from my terminal history and does not show up in the logs (since it occurs outside Rails).

From the many requests that are working and the fact that it fails in different places, I'm guessing that it is due to some local system limitation.

like image 986
SamuelLJohnson Avatar asked Jan 24 '20 04:01

SamuelLJohnson


1 Answers

After attempting a couple of different fixes, I eventually discovered that the issue was my open files limit. To check it, run ulimit -n in a terminal. Mine was set to 256.

I followed the instructions in this article: https://wilsonmar.github.io/maximum-limits/

The specific instructions start at the "Sierra and newer versions" header and go to "Their permissions need to be “-rw-r–r–”, set by sudo chmod 644." under #5. After adding the files and changing ownership and permission, I restarted and the open file limit is now 524288.

I now have no further issues with rapid API calls.

like image 117
SamuelLJohnson Avatar answered Nov 18 '22 05:11

SamuelLJohnson