Repository: pytorch
Issue: RuntimeError: Shared memory manager connection has timed out
Labels: module: multiprocessing,triaged

### 🐛 Describe the bug

I have RuntimeError: Shared memory manager connection has timed out when I try to do a training with more than 0 workers.
I'm running the training inside a docker container.
```
Traceback (most recent call last):                                                                                                                                                                                               
  File "/home/davide/code/cli.py", line 140, in __init__                                                                       
    super().__init__(                                                                                                                                                                                                            
  File "/home/davide/cim-venv/lib/python3.8/site-packages/pytorch_lightning/cli.py", line 386, in __init__                                                                                                               
    self._run_subcommand(self.subcommand)                                                                                                                                                                                        
  File "/home/davide/code/cli.py", line 438, in _run_subcommand                                                                
    fn(**fn_kwargs)                                                                                                                                                                                                              
  File "/home/davide/cim-venv/lib/python3.8/site-packages/pytorch_lightning/trainer/trainer.py", line 544, in fit                                                                                                        
    call._call_and_handle_interrupt(                                                                                                                                                                                             
  File "/home/davide/cim-venv/lib/python3.8/site-packages/pytorch_lightning/trainer/call.py", line 44, in _call_and_handle_interrupt                                                                                     
    return trainer_fn(*args, **kwargs)                                                                                                                                                                                           
  File "/home/davide/cim-venv/lib/python3.8/site-packages/pytorch_lightning/trainer/trainer.py", line 580, in _fit_impl                                                                                                  
    self._run(model, ckpt_path=ckpt_path)                                                                                                                                                                                        
  File "/home/davide/cim-venv/lib/python3.8/site-packages/pytorch_lightning/trainer/trainer.py", line 989, in _run
    results = self._run_stage()
  File "/home/davide/cim-venv/lib/python3.8/site-packages/pytorch_lightning/trainer/trainer.py", line 1035, in _run_stage
    self.fit_loop.run()
  File "/home/davide/cim-venv/lib/python3.8/site-packages/pytorch_lightning/loops/fit_loop.py", line 202, in run
    self.advance()
  File "/home/davide/cim-venv/lib/python3.8/site-packages/pytorch_lightning/loops/fit_loop.py", line 359, in advance
    self.epoch_loop.run(self._data_fetcher)
  File "/home/davide/cim-venv/lib/python3.8/site-packages/pytorch_lightning/loops/training_epoch_loop.py", line 136, in run
    self.advance(data_fetcher)
  File "/home/davide/cim-venv/lib/python3.8/site-packages/pytorch_lightning/loops/training_epoch_loop.py", line 202, in advance
    batch, _, __ = next(data_fetcher)                                                                                                                                                                                            
  File "/home/davide/cim-venv/lib/python3.8/site-packages/pytorch_lightning/loops/fetchers.py", line 127, in __next__                                                                                                    
    batch = super().__next__()                                                                                                                                                                                                   
  File "/home/davide/cim-venv/lib/python3.8/site-packages/pytorch_lightning/loops/fetchers.py", line 56, in __next__                                                                                                     
    batch = next(self.iterator)                                                                                                                                                                                                  
  File "/home/davide/cim-venv/lib/python3.8/site-packages/pytorch_lightning/utilities/combined_loader.py", line 326, in __next__                                                                                         
    out = next(self._iterator)                                                                                                                                                                                                   
  File "/home/davide/cim-venv/lib/python3.8/site-packages/pytorch_lightning/utilities/combined_loader.py", line 74, in __next__                                                                                          
    out[i] = next(self.iterators[i])                                                                                                                                                                                             
  File "/home/davide/code/c_data_loader.py", line 238, in __iter__                                           
    yield *next(iterator), name                                                                                                                                                                                                  
  File "/home/davide/cim-venv/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 630, in __next__                                                                                                         
    data = self._next_data()                                                                                                                                                                                                     
  File "/home/davide/cim-venv/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1328, in _next_data                                                                                                      
    idx, data = self._get_data()                                                                                                                                                                                                 
  File "/home/davide/cim-venv/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1294, in _get_data                                                                                                       
    success, data = self._try_get_data()                                                                                                                                                                                         
  File "/home/davide/cim-venv/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1132, in _try_get_data                                                                                                   
    data = self._data_queue.get(timeout=timeout)                                                                                                                                                                                      
  File "/usr/lib/python3.8/multiprocessing/queues.py", line 116, in get                                                                                                                                                          
    return _ForkingPickler.loads(res)                                                                                                                                                                                            
  File "/home/davide/cim-venv/lib/python3.8/site-packages/torch/multiprocessing/reductions.py", line 374, in rebuild_storage_filename                                                                                    
    storage = torch.UntypedStorage._new_shared_filename_cpu(manager, handle, size)                                                                                                                                               
RuntimeError: Shared memory manager connection has timed out  
```

### Versions

Collecting environment information...
PyTorch version: 2.1.2+cu121
Is debug build: False
CUDA used to build PyTorch: 12.1
ROCM used to build PyTorch: N/A

OS: Ubuntu 20.04.6 LTS (x86_64)
GCC version: (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0
Clang version: 10.0.0-4ubuntu1 
CMake version: version 3.26.1
Libc version: glibc-2.31

Python version: 3.8.10 (default, Nov 22 2023, 10:22:35)  [GCC 9.4.0] (64-bit runtime)
Python platform: Linux-6.5.0-41-generic-x86_64-with-glibc2.29
Is CUDA available: True
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: NVIDIA GeForce RTX 4090
Nvidia driver version: 535.183.01
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture:                       x86_64
CPU op-mode(s):                     32-bit, 64-bit
Byte Order:                         Little Endian
Address sizes:                      48 bits physical, 48 bits virtual
CPU(s):                             32
On-line CPU(s) list:                0-31
Thread(s) per core:                 2
Core(s) per socket:                 16
Socket(s):                          1
NUMA node(s):                       1
Vendor ID:                          AuthenticAMD
CPU family:                         25
Model:                              97
Model name:                         AMD Ryzen 9 7950X 16-Core Processor
Stepping:                           2
CPU MHz:                            3135.432
CPU max MHz:                        5881.0000
CPU min MHz:                        400.0000
BogoMIPS:                           8983.11
Virtualization:                     AMD-V
L1d cache:                          512 KiB
L1i cache:                          512 KiB
L2 cache:                           16 MiB
L3 cache:                           64 MiB
NUMA node0 CPU(s):                  0-31
Vulnerability Gather data sampling: Not affected
Vulnerability Itlb multihit:        Not affected
Vulnerability L1tf:                 Not affected
Vulnerability Mds:                  Not affected
Vulnerability Meltdown:             Not affected
Vulnerability Mmio stale data:      Not affected
Vulnerability Retbleed:             Not affected
Vulnerability Spec rstack overflow: Vulnerable: Safe RET, no microcode
Vulnerability Spec store bypass:    Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:           Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:           Mitigation; Enhanced / Automatic IBRS; IBPB conditional; STIBP always-on; RSB filling; PBRSB-eIBRS Not affected; BHI Not affected
Vulnerability Srbds:                Not affected
Vulnerability Tsx async abort:      Not affected
Flags:                              fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good amd_lbr_v2 nopl nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb cat_l3 cdp_l3 hw_pstate ssbd mba perfmon_v2 ibrs ibpb stibp ibrs_enhanced vmmcall fsgsbase bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local avx512_bf16 clzero irperf xsaveerptr rdpru wbnoinvd cppc arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif x2avic v_spec_ctrl vnmi avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq rdpid overflow_recov succor smca fsrm flush_l1d

Versions of relevant libraries:
[pip3] mypy==1.10.0
[pip3] mypy-extensions==1.0.0
[pip3] numpy==1.23.5
[pip3] onnx==1.16.0
[pip3] onnx-graphsurgeon==0.3.27
[pip3] onnx-simplifier==0.4.8
[pip3] onnx_utils==0.1.0
[pip3] onnxruntime==1.18.0
[pip3] pie-torch==0.0.1
[pip3] pytorch-lightning==2.1.2
[pip3] pytorch-msssim==1.0.0
[pip3] torch==2.1.2
[pip3] torch-fidelity==0.3.0
[pip3] torch-tb-profiler==0.4.3
[pip3] torchmetrics==1.4.0.post0
[pip3] torchvision==0.16.2
[pip3] triton==2.1.0
[conda] No relevant packages


cc @VitalyFedyunin