Repository: pytorch
Issue: Questions about TCPStoreLibUV
Labels: oncall: distributed,triaged

### 🐛 Describe the bug

When I run the following code with torch2.3.1, the core file is generated
```
class TorchNpuRunStoreSample:
    def __init__(self, protocol: str, ip: str, port: int, run_time: str):
        self._current_rank = int(os.getenv('RANK', 0))
        self._world_size = int(os.getenv('WORLD_SIZE', 0))
        self._init_method = f'{protocol}://{ip}:{port}?use_libuv=1'
        self._timeout = timedelta(minutes=1)
        self._key = 'sample_torch_npu_run_store:test_case_001'

        self._run_time = datetime.strptime(run_time, '%Y-%m-%d_%H:%M:%S')

    def create_store(self):
        rendezvous_iterator = rendezvous(
            self._init_method, self._current_rank, self._world_size, timeout=self._timeout
        )

        self._store, self._current_rank, self._world_size = next(rendezvous_iterator)
        self._store.set_timeout(self._timeout)
        self._store = PrefixStore("default_pg", self._store)

    def wait_time_to_start(self):
        now = datetime.now()
        time_difference = self._run_time - now
        seconds_to_wait = int(time_difference.total_seconds())
        if seconds_to_wait <= 0:
            print(f'!!!!! Rank: {self._current_rank} start too late')
            return

        print(f'Rank: {self._current_rank} will sleep {seconds_to_wait}')
        time.sleep(seconds_to_wait)

    def store_based_barrier(self, key2=''):
        logging.info(f'barrier begin Rank: {self._current_rank} add key: {self._key}{key2} first time')
        self._store.add(f'{self._key}{key2}', 1)

        start_time = time.time()
        alive_count = self._store.add(f'{self._key}{key2}', 0)
        while alive_count != self._world_size:
            time.sleep(0.01)
            alive_count = self._store.add(f'{self._key}{key2}', 0)
            if alive_count == self._world_size:
                break
            if timedelta(seconds=(time.time() - start_time)) > self._timeout:
                logging.error(f'for key {self._key}{key2} now count={alive_count}')
                timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
                raise RuntimeError(f'[{timestamp}]rank: {self._current_rank} {self._key}{key2} wait workers timeout')
```

Perform the following startup:
`torchrun --nproc-per-node=3 --nnodes=1 --max-restarts=0 --rdzv-backend=c10d --rdzv-endpoint=localhost:29515 sample_worker.py`

The stack information for core is as follows：
```
#0  0x00007fa767cc1387 in raise () from /lib64/libc.so.6
#1  0x00007fa767cc2a78 in abort () from /lib64/libc.so.6
#2  0x00007fa74864e35a in __cxxabiv1::__terminate(void (*)()) ()
    at /opt/conda/conda-bld/gcc-compiler_1654084175708/work/build/gcc-final/x86_64-conda-linux-gnu/libstdc++-v3/libsupc++/eh_terminate.cc:48
#3  0x00007fa74864d3b9 in __cxa_call_terminate (ue_header=0x56bc6f0)
    at /opt/conda/conda-bld/gcc-compiler_1654084175708/work/build/gcc-final/x86_64-conda-linux-gnu/libstdc++-v3/libsupc++/eh_call.cc:54
#4  0x00007fa74864dae7 in __gxx_personality_v0 ()
    at /opt/conda/conda-bld/gcc-compiler_1654084175708/work/build/gcc-final/x86_64-conda-linux-gnu/libstdc++-v3/libsupc++/eh_personality.cc:685
#5  0x00007fa7483968e3 in ?? () from /lib64/libgcc_s.so.1
#6  0x00007fa748396c7b in _Unwind_RaiseException () from /lib64/libgcc_s.so.1
#7  0x00007fa74864e64b in __cxxabiv1::__cxa_throw (obj=<optimized out>, tinfo=0x7fa7487a4530 <typeinfo for std::system_error>, 
    dest=0x7fa748678920 <std::system_error::~system_error()>)
    at /opt/conda/conda-bld/gcc-compiler_1654084175708/work/build/gcc-final/x86_64-conda-linux-gnu/libstdc++-v3/libsupc++/eh_throw.cc:90
#8  0x00007fa7486455e8 in std::__throw_system_error (__i=22)
    at /opt/conda/conda-bld/gcc-compiler_1654084175708/work/build/gcc-final/x86_64-conda-linux-gnu/libstdc++-v3/include/alloc_traits.h:89
#9  0x00007fa748678e50 in std::thread::join (this=0x56c03f0)
    at /opt/conda/conda-bld/gcc-compiler_1654084175708/work/gcc/libstdc++-v3/src/c++11/shared_ptr_base.h:115
#10 0x00007fa74e49f6f5 in c10d::detail::LibUVStoreDaemon::~LibUVStoreDaemon() ()
   from /root/miniconda3/envs/tpq2.4/lib/python3.8/site-packages/torch/lib/libtorch_cpu.so
#11 0x00007fa74e49f789 in c10d::detail::LibUVStoreDaemon::~LibUVStoreDaemon() ()
   from /root/miniconda3/envs/tpq2.4/lib/python3.8/site-packages/torch/lib/libtorch_cpu.so
#12 0x00007fa749fd0f8c in c10d::detail::create_libuv_tcpstore_backend(c10d::TCPStoreOptions const&) [clone .cold] ()
   from /root/miniconda3/envs/tpq2.4/lib/python3.8/site-packages/torch/lib/libtorch_cpu.so
#13 0x00007fa74e496ef8 in c10d::detail::TCPServer::start(c10d::TCPStoreOptions const&) ()
   from /root/miniconda3/envs/tpq2.4/lib/python3.8/site-packages/torch/lib/libtorch_cpu.so
#14 0x00007fa74e497746 in c10d::TCPStore::TCPStore(std::string, c10d::TCPStoreOptions const&) ()
   from /root/miniconda3/envs/tpq2.4/lib/python3.8/site-packages/torch/lib/libtorch_cpu.so
#15 0x00007fa760bd9b65 in void pybind11::cpp_function::initialize<void pybind11::detail::initimpl::factory<torch::distributed::c10d::(anonymous namespace)::c10d_init(_object*, _object*)::{lambda(std::string const&, unsigned short, std::optional<int>, bool, std::chrono::duration<long, std::ratio<1l, 1000l> >, bool, bool, std::optional<int>, bool)#35}, pybind11::detail::void_type (*)(), c10::intrusive_ptr<c10d::TCPStore, pybind11::detail::void_type (*)()::detail::intrusive_target_default_null_type<c10d> > (std::string const&, unsigned short, std::optional<int>, bool, std::chrono::duration<long, std::ratio<1l, 1000l> >, bool, bool, std::optional<int>, bool), pybind11::detail::void_type>::execute<pybind11::class_<c10d, pybind11::detail::void_type (*)()::detail::intrusive_target_default_null_type<c10d> >, pybind11::arg, pybind11::class_<c10d, pybind11::detail::void_type (*)()::detail::intrusive_target_default_null_type<c10d> >, pybind11::arg_v, pybind11::arg, pybind11::arg, pybind11::arg, pybind11::arg, pybind11::arg, pybind11::arg, pybind11::call_guard<pybind11::gil_scoped_release> >(pybind11::class_<c10d, pybind11::detail::void_type (*)()::detail::intrusive_target_default_null_type<c10d> >&, pybind11::arg const&, pybind11::class_<c10d, pybind11::detail::void_type (*)()::detail::intrusive_target_default_null_type<c10d> > const&, pybind11::arg_v const&, pybind11::arg const&, pybind11::arg const&, pybind11::arg const&, pybind11::arg const&, pybind11::arg const&, pybind11::arg const&, pybind11::call_guard<pybind11::gil_scoped_release> const&) &&::{lambda(pybind11::detail::value_and_holder&, std::string const&, unsigned short, std::optional<int>, bool, std::chrono::duration<long, std::ratio<1l, 1000l> >, bool, bool, std::optional<int>, bool)#1}, void, pybind11::detail::value_and_holder, std::string const&, unsigned short, std::optional<int>, bool, std::chrono::duration<long, std::ratio<1l, 1000l> >, bool, bool, std::optional<int>, bool, pybind11::name, pybind11::is_method, pybind11::sibling, pybind11::detail::is_new_style_constructor, pybind11::class_<c10d, pybind11::detail::void_type (*)()::detail::intrusive_target_default_null_type<c10d> >, pybind11::class_<c10d, pybind11::detail::void_type (*)()::detail::intrusive_target_default_null_type<c10d> >, pybind11::arg, pybind11::arg, pybind11::arg, pybind11::arg, pybind11::arg, pybind11::arg, pybind11::arg, pybind11::gil_scoped_release>(pybind11::call_guard<pybind11::gil_scoped_release>&&, void (*)(pybind11::detail::value_and_holder, std::string const&, unsigned short, std::optional<int>, bool, std::chrono::duration<long, std::ratio<1l, 1000l> >, bool, bool, std::optional<int>, bool), pybind11::name const&, pybind11::is_method const&, pybind11::sibling const&, pybind11::detail::is_new_style_constructor const&, pybind11::class_<c10d, pybind11::detail::void_type (*)()::detail::intrusive_target_default_null_type<c10d> > const&, pybind11::class_<c10d, pybind11::detail::void_type (*)()::detail::intrusive_target_default_null_type<c10d> > const&, pybind11::arg const&, pybind11::arg const&, pybind11::arg const&, pybind11::arg const&, pybind11::arg const&, pybind11::arg const&, pybind11::arg const&, pybind11::gil_scoped_release const&)::{lambda(pybind11::detail::function_call&)#3}::_FUN
    () from /root/miniconda3/envs/tpq2.4/lib/python3.8/site-packages/torch/lib/libtorch_python.so
```


### Versions

Collecting environment information...
PyTorch version: 2.3.1+cpu
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: CentOS Linux 7 (Core) (x86_64)
GCC version: (GCC) 7.5.0
Clang version: Could not collect
CMake version: version 3.20.5
Libc version: glibc-2.17

Python version: 3.8.18 (default, Sep 11 2023, 13:40:15)  [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-3.10.0-957.el7.x86_64-x86_64-with-glibc2.17
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
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
CPU(s):                96
On-line CPU(s) list:   0-95
Thread(s) per core:    2
Core(s) per socket:    24
Socket(s):             2
NUMA node(s):          2
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 85
Model name:            Intel(R) Xeon(R) Platinum 8260 CPU @ 2.40GHz
Stepping:              7
CPU MHz:               1000.000
CPU max MHz:           2401.0000
CPU min MHz:           1000.0000
BogoMIPS:              4800.00
Virtualization:        VT-x
L1d cache:             32K
L1i cache:             32K
L2 cache:              1024K
L3 cache:              36608K
NUMA node0 CPU(s):     0-23,48-71
NUMA node1 CPU(s):     24-47,72-95
Flags:                 fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch epb cat_l3 cdp_l3 intel_pt ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm mpx rdt_a avx512f avx512dq rdseed adx smap clflushopt clwb avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts pku ospke avx512_vnni spec_ctrl intel_stibp flush_l1d arch_capabilities

Versions of relevant libraries:
[pip3] numpy==1.23.5
[pip3] torch==2.3.1+cpu
[pip3] torch-npu==2.3.1.post20240612
[pip3] torchvision==0.18.1
[conda] numpy                     1.23.5                   pypi_0    pypi
[conda] torch                     2.3.1+cpu                pypi_0    pypi
[conda] torch-npu                 2.3.1.post20240612          pypi_0    pypi
[conda] torchvision               0.18.1                   pypi_0    pypi

cc @mrshenli @pritamdamania87 @zhaojuanmao @satgera @gqchen @aazzolini @osalpekar @jiayisuse @H-Huang @kwen2501 @awgu @penguinwu @fegin @XilunWu @wanchaol @fduwjj @wz337 @tianyu-l @wconstab @yf225 @chauhang @d4l3k