Repository: pytorch
Issue: c10:Error: could not unlink the shared memory file
Labels: module: multiprocessing,module: dataloader,triaged,better-engineering

## 🐛 Bug

Torch fails while trying to `shm_unlink()`. Stack trace below. Is there a way to get the `shm_unlink` *errno*?

## To Reproduce

I am using shared memory for dataloading (via torch's dataloader) and Queues from torch.multiprocessing for async summary writing. This error randomly happens at some point during the training.
Fyi I am using `torch.multiprocessing.set_sharing_strategy("file_system")`.

<!-- If you have a code sample, error messages, stack traces, please provide it here as well -->

```
terminate called after throwing an instance of 'c10::Error'
  what():  could not unlink the shared memory file /torch_30417_1951398734 (close at /opt/conda/conda-bld/pytorch_1570710718161/work/aten/src/TH/THAllocator.cpp:475)
frame #0: c10::Error::Error(c10::SourceLocation, std::string const&) + 0x47 (0x7f4842428687 in /cluster/schroeter/miniconda/envs/clc-lme50/lib/python3.7/site-packages/torch/lib/libc10.so)
frame #1: THRefcountedMapAllocator::close() + 0x13c (0x7f4845cb3efc in /cluster/schroeter/miniconda/envs/clc-lme50/lib/python3.7/site-packages/torch/lib/libtorch.so)
frame #2: THManagedMapAllocator::close() + 0x42 (0x7f4875ee7ee2 in /cluster/schroeter/miniconda/envs/clc-lme50/lib/python3.7/site-packages/torch/lib/libshm.so)
frame #3: <unknown function> + 0x503c (0x7f4875ee803c in /cluster/schroeter/miniconda/envs/clc-lme50/lib/python3.7/site-packages/torch/lib/libshm.so)
frame #4: c10::TensorImpl::release_resources() + 0x4d (0x7f4842415e9d in /cluster/schroeter/miniconda/envs/clc-lme50/lib/python3.7/site-packages/torch/lib/libc10.so)
frame #5: <unknown function> + 0x1c8439 (0x7f48753a9439 in /cluster/schroeter/miniconda/envs/clc-lme50/lib/python3.7/site-packages/torch/lib/libtorch_python.so)
frame #6: <unknown function> + 0x4b19ab (0x7f48756929ab in /cluster/schroeter/miniconda/envs/clc-lme50/lib/python3.7/site-packages/torch/lib/libtorch_python.so)
frame #7: <unknown function> + 0x4b19e6 (0x7f48756929e6 in /cluster/schroeter/miniconda/envs/clc-lme50/lib/python3.7/site-packages/torch/lib/libtorch_python.so)
frame #8: <unknown function> + 0x1a184f (0x561be00ed84f in python train.py /cluster/schroeter/configs/clc/conv_rmse1.cfg /scratch/schroeter/clc-data)
frame #9: <unknown function> + 0x10db9b (0x561be0059b9b in python train.py /cluster/schroeter/configs/clc/conv_rmse1.cfg /scratch/schroeter/clc-data)
frame #10: <unknown function> + 0x1a1831 (0x561be00ed831 in python train.py /cluster/schroeter/configs/clc/conv_rmse1.cfg /scratch/schroeter/clc-data)
frame #11: PyDict_SetItem + 0x502 (0x561be00aeed2 in python train.py /cluster/schroeter/configs/clc/conv_rmse1.cfg /scratch/schroeter/clc-data)
frame #12: _PyObjectDict_SetItem + 0x54 (0x561be00b55c4 in python train.py /cluster/schroeter/configs/clc/conv_rmse1.cfg /scratch/schroeter/clc-data)
frame #13: _PyObject_GenericSetAttrWithDict + 0x87 (0x561be010e827 in python train.py /cluster/schroeter/configs/clc/conv_rmse1.cfg /scratch/schroeter/clc-data)
frame #14: PyObject_SetAttr + 0x67 (0x561be010f527 in python train.py /cluster/schroeter/configs/clc/conv_rmse1.cfg /scratch/schroeter/clc-data)
frame #15: _PyEval_EvalFrameDefault + 0xdca (0x561be01181ba in python train.py /cluster/schroeter/configs/clc/conv_rmse1.cfg /scratch/schroeter/clc-data)
frame #16: _PyFunction_FastCallKeywords + 0xfb (0x561be00afccb in python train.py /cluster/schroeter/configs/clc/conv_rmse1.cfg /scratch/schroeter/clc-data)
frame #17: _PyEval_EvalFrameDefault + 0x6a3 (0x561be0117a93 in python train.py /cluster/schroeter/configs/clc/conv_rmse1.cfg /scratch/schroeter/clc-data)
frame #18: _PyFunction_FastCallKeywords + 0xfb (0x561be00afccb in python train.py /cluster/schroeter/configs/clc/conv_rmse1.cfg /scratch/schroeter/clc-data)
frame #19: _PyEval_EvalFrameDefault + 0x6a3 (0x561be0117a93 in python train.py /cluster/schroeter/configs/clc/conv_rmse1.cfg /scratch/schroeter/clc-data)
frame #20: _PyEval_EvalCodeWithName + 0x2f9 (0x561be0060539 in python train.py /cluster/schroeter/configs/clc/conv_rmse1.cfg /scratch/schroeter/clc-data)
frame #21: _PyFunction_FastCallDict + 0x400 (0x561be0061860 in python train.py /cluster/schroeter/configs/clc/conv_rmse1.cfg /scratch/schroeter/clc-data)
frame #22: _PyEval_EvalFrameDefault + 0x1e42 (0x561be0119232 in python train.py /cluster/schroeter/configs/clc/conv_rmse1.cfg /scratch/schroeter/clc-data)
frame #23: _PyEval_EvalCodeWithName + 0xac9 (0x561be0060d09 in python train.py /cluster/schroeter/configs/clc/conv_rmse1.cfg /scratch/schroeter/clc-data)
frame #24: _PyFunction_FastCallKeywords + 0x387 (0x561be00aff57 in python train.py /cluster/schroeter/configs/clc/conv_rmse1.cfg /scratch/schroeter/clc-data)
frame #25: _PyEval_EvalFrameDefault + 0x14dc (0x561be01188cc in python train.py /cluster/schroeter/configs/clc/conv_rmse1.cfg /scratch/schroeter/clc-data)
frame #26: _PyFunction_FastCallKeywords + 0xfb (0x561be00afccb in python train.py /cluster/schroeter/configs/clc/conv_rmse1.cfg /scratch/schroeter/clc-data)
frame #27: _PyEval_EvalFrameDefault + 0x4b39 (0x561be011bf29 in python train.py /cluster/schroeter/configs/clc/conv_rmse1.cfg /scratch/schroeter/clc-data)
frame #28: _PyFunction_FastCallKeywords + 0xfb (0x561be00afccb in python train.py /cluster/schroeter/configs/clc/conv_rmse1.cfg /scratch/schroeter/clc-data)
frame #29: _PyEval_EvalFrameDefault + 0x416 (0x561be0117806 in python train.py /cluster/schroeter/configs/clc/conv_rmse1.cfg /scratch/schroeter/clc-data)
frame #30: _PyEval_EvalCodeWithName + 0x2f9 (0x561be0060539 in python train.py /cluster/schroeter/configs/clc/conv_rmse1.cfg /scratch/schroeter/clc-data)
frame #31: PyEval_EvalCodeEx + 0x44 (0x561be0061424 in python train.py /cluster/schroeter/configs/clc/conv_rmse1.cfg /scratch/schroeter/clc-data)
frame #32: PyEval_EvalCode + 0x1c (0x561be006144c in python train.py /cluster/schroeter/configs/clc/conv_rmse1.cfg /scratch/schroeter/clc-data)
frame #33: <unknown function> + 0x22ab74 (0x561be0176b74 in python train.py /cluster/schroeter/configs/clc/conv_rmse1.cfg /scratch/schroeter/clc-data)
frame #34: PyRun_FileExFlags + 0xa1 (0x561be0180eb1 in python train.py /cluster/schroeter/configs/clc/conv_rmse1.cfg /scratch/schroeter/clc-data)
frame #35: PyRun_SimpleFileExFlags + 0x1c3 (0x561be01810a3 in python train.py /cluster/schroeter/configs/clc/conv_rmse1.cfg /scratch/schroeter/clc-data)
frame #36: <unknown function> + 0x236195 (0x561be0182195 in python train.py /cluster/schroeter/configs/clc/conv_rmse1.cfg /scratch/schroeter/clc-data)
frame #37: _Py_UnixMain + 0x3c (0x561be01822bc in python train.py /cluster/schroeter/configs/clc/conv_rmse1.cfg /scratch/schroeter/clc-data)
frame #38: __libc_start_main + 0xe7 (0x7f48846f8b97 in /lib/x86_64-linux-gnu/libc.so.6)
frame #39: <unknown function> + 0x1db062 (0x561be0127062 in python train.py /cluster/schroeter/configs/clc/conv_rmse1.cfg /scratch/schroeter/clc-data)
```

## Expected behavior

Don't throw this c10 Error, or provide better error details, i.e. the shm_unlink errno.

## Environment
Running on ubuntu 18:10, torch 1.3.0.


cc @SsnL