Repository: pytorch
Issue: Multiple GPUs get  "errno: 98 - Address already in use"
Labels: oncall: distributed,triaged,module: c10d

### 🐛 Describe the bug

I run the train.py 
torchrun --nnodes=1 --nproc_per_node=1 train.py --local_rank 0
it is run, but just one GPU,
when I run 
torchrun --standalone --nnodes=1 --nproc_per_node=2 train.py --local_rank 0

 get a error

```
torchrun --standalone --nnodes=1 --nproc_per_node=2 train.py --local_rank 0
WARNING:torch.distributed.run:
*****************************************
Setting OMP_NUM_THREADS environment variable for each process to be 1 in default, to avoid your system being overloaded, please further tune the variable for optimal performance in your application as needed.
*****************************************
[W socket.cpp:401] [c10d] The server socket has failed to listen on [::]:47531 (errno: 98 - Address already in use).
[W socket.cpp:401] [c10d] The server socket has failed to bind to 0.0.0.0:47531 (errno: 98 - Address already in use).
[E socket.cpp:435] [c10d] The server socket has failed to listen on any local network address.
Traceback (most recent call last):
  File "train.py", line 180, in <module>
    train()
  File "train.py", line 47, in train
    dist.init_process_group(
  File "/home/wupeng/anaconda3/envs/ldm/lib/python3.8/site-packages/torch/distributed/distributed_c10d.py", line 595, in init_process_group
    store, rank, world_size = next(rendezvous_iterator)
  File "/home/wupeng/anaconda3/envs/ldm/lib/python3.8/site-packages/torch/distributed/rendezvous.py", line 232, in _env_rendezvous_handler
    store = _create_c10d_store(master_addr, master_port, rank, world_size, timeout)
  File "/home/wupeng/anaconda3/envs/ldm/lib/python3.8/site-packages/torch/distributed/rendezvous.py", line 160, in _create_c10d_store
    return TCPStore(
RuntimeError: The server socket has failed to listen on any local network address. The server socket has failed to listen on [::]:47531 (errno: 98 - Address already in use). The server socket has failed to bind to 0.0.0.0:47531 (errno: 98 - Address already in use).
WARNING:torch.distributed.elastic.multiprocessing.api:Sending process 18620 closing signal SIGTERM
ERROR:torch.distributed.elastic.multiprocessing.api:failed (exitcode: 1) local_rank: 1 (pid: 18621) of binary: /home/wupeng/anaconda3/envs/ldm/bin/python
Traceback (most recent call last):
  File "/home/wupeng/anaconda3/envs/ldm/bin/torchrun", line 33, in <module>
    sys.exit(load_entry_point('torch==1.11.0', 'console_scripts', 'torchrun')())
  File "/home/wupeng/anaconda3/envs/ldm/lib/python3.8/site-packages/torch/distributed/elastic/multiprocessing/errors/__init__.py", line 345, in wrapper
    return f(*args, **kwargs)
  File "/home/wupeng/anaconda3/envs/ldm/lib/python3.8/site-packages/torch/distributed/run.py", line 724, in main
    run(args)
  File "/home/wupeng/anaconda3/envs/ldm/lib/python3.8/site-packages/torch/distributed/run.py", line 715, in run
    elastic_launch(
  File "/home/wupeng/anaconda3/envs/ldm/lib/python3.8/site-packages/torch/distributed/launcher/api.py", line 131, in __call__
    return launch_agent(self._config, self._entrypoint, list(args))
  File "/home/wupeng/anaconda3/envs/ldm/lib/python3.8/site-packages/torch/distributed/launcher/api.py", line 245, in launch_agent
    raise ChildFailedError(
torch.distributed.elastic.multiprocessing.errors.ChildFailedError:
============================================================
train.py FAILED
------------------------------------------------------------
Failures:
  <NO_OTHER_FAILURES>
------------------------------------------------------------
Root Cause (first observed failure):
[0]:
  time      : 2022-09-25_19:36:17
  host      : Double-1080ti
  rank      : 1 (local_rank: 1)
  exitcode  : 1 (pid: 18621)
  error_file: <N/A>
  traceback : To enable traceback see: https://pytorch.org/docs/stable/elastic/errors.html
============================================================
```



### Versions

pytorch version is: v1.11.0

cc @pietern @mrshenli @pritamdamania87 @zhaojuanmao @satgera @rohan-varma @gqchen @aazzolini @osalpekar @jiayisuse @SciPioneer @H-Huang @kwen2501