Windows下Rails用rpush启动报错:uninitialized constant Process::RLIMIT_NOFILE
uninitialized constant Process::RLIMIT_NOFILE Error with rpush on Windows Hey there! I’ve dealt with this exact problem when setting up rpush on Windows, so I know how annoying that error can be. Let’s walk through the fixes step by step.
The Root Cause
As you noted, the Process::RLIMIT_NOFILE constant is Unix-only—Windows doesn’t expose this system API, which is why the DEFAULT_POOL_SIZE definition in persistent.rb breaks when you run rpush start.
Solution 1: Modify the rpush Gem’s Source Code (Quick Fix)
Locate the persistent.rb file:
First, find where the rpush gem is installed on your system. Run this command in your terminal:bundle show rpushThis will output the full path to the gem. Navigate to the daemon directory inside it—usually something like
[gem_path]/lib/rpush/daemon/.Edit the DEFAULT_POOL_SIZE definition:
Openpersistent.rbin a text editor. Look for the line that setsDEFAULT_POOL_SIZE(it probably looks like this):DEFAULT_POOL_SIZE = Process.getrlimit(Process::RLIMIT_NOFILE)[0] / 4Replace it with a Windows-compatible check:
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/ # Set a reasonable fixed pool size for Windows DEFAULT_POOL_SIZE = 512 else # Keep the original Unix logic DEFAULT_POOL_SIZE = Process.getrlimit(Process::RLIMIT_NOFILE)[0] / 4 endSave and test:
Save the file, then runrpush startagain. The error should be gone.
Solution 2: Use a Monkey Patch (Permanent, Gem-Safe Fix)
If you don’t want to modify the gem directly (since gem updates will overwrite your changes), use a monkey patch in your Rails project:
Create an initializer file:
In your Rails app, create a new file atconfig/initializers/rpush_windows_fix.rb.Add the patch code:
Paste this into the file:module Rpush module Daemon module Persistent # Override DEFAULT_POOL_SIZE for Windows systems if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/ DEFAULT_POOL_SIZE = 512 end end end endRestart your Rails server (if running):
The initializer will load when your app starts, overriding the problematic constant for Windows. Now runrpush start—it should work without errors.
Why This Works
By checking the host OS first, we avoid referencing the Unix-only Process::RLIMIT_NOFILE constant on Windows. The fixed pool size of 512 is a reasonable default that works for most rpush use cases on Windows.
内容的提问来源于stack exchange,提问作者Pinki

