YugJ commited on
Commit
e7e449f
·
verified ·
1 Parent(s): 648c076

Upload sandbox.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. sandbox.py +13 -14
sandbox.py CHANGED
@@ -146,20 +146,19 @@ def _preexec():
146
  resource.setrlimit(resource.RLIMIT_AS, (mem, mem))
147
  resource.setrlimit(resource.RLIMIT_FSIZE, (64 * 1024 * 1024, 64 * 1024 * 1024))
148
 
149
- # RLIMIT_NPROC counts processes per *user*, not per process tree, so it
150
- # includes everything the container is already running under this uid. A
151
- # tight cap here made rustc fail to spawn its own threads:
152
- # Os { code: 11, kind: WouldBlock, message: "Resource temporarily unavailable" }
153
- # Set high enough that a compiler's thread pool always fits, while still
154
- # bounding a runaway fork loop. Never lower than the existing soft limit,
155
- # since raising it back is not permitted for an unprivileged process.
156
- try:
157
- soft, hard = resource.getrlimit(resource.RLIMIT_NPROC)
158
- target = 4096 if hard == resource.RLIM_INFINITY else min(4096, hard)
159
- if soft == resource.RLIM_INFINITY or target > soft:
160
- resource.setrlimit(resource.RLIMIT_NPROC, (target, hard))
161
- except (ValueError, OSError):
162
- pass # not fatal - CPU time, memory, and the wall-clock kill still apply
163
  # New process group so a timeout kill takes any children with it.
164
  os.setsid()
165
 
 
146
  resource.setrlimit(resource.RLIMIT_AS, (mem, mem))
147
  resource.setrlimit(resource.RLIMIT_FSIZE, (64 * 1024 * 1024, 64 * 1024 * 1024))
148
 
149
+ # RLIMIT_NPROC is deliberately NOT set.
150
+ #
151
+ # It counts processes per *user*, not per process tree, so any cap here also
152
+ # counts every thread the host container already runs under this uid. In
153
+ # practice that starved the compilers of threads:
154
+ # rustc: Os { code: 11, kind: WouldBlock, ... }
155
+ # g++: cannot execute cc1plus: vfork: Resource temporarily unavailable
156
+ # Both are EAGAIN from the fork itself. Because the limit is shared with
157
+ # processes we did not start and cannot count, any value is either too low
158
+ # to compile or too high to matter - it is not a usable control here.
159
+ #
160
+ # A fork bomb is still bounded by RLIMIT_CPU, RLIMIT_AS, and the wall-clock
161
+ # kill, which terminates the entire process group.
 
162
  # New process group so a timeout kill takes any children with it.
163
  os.setsid()
164