@@ -726,14 +726,30 @@ def start(self, params=[], wait=True):
726
726
"start"
727
727
] + params # yapf: disable
728
728
729
- try :
730
- exit_status , out , error = execute_utility (_params , self .utils_log_file , verbose = True )
731
- if error and 'does not exist' in error :
732
- raise Exception
733
- except Exception as e :
734
- msg = 'Cannot start node'
735
- files = self ._collect_special_files ()
736
- raise_from (StartNodeException (msg , files ), e )
729
+ startup_retries = 5
730
+ while True :
731
+ try :
732
+ exit_status , out , error = execute_utility (_params , self .utils_log_file , verbose = True )
733
+ if error and 'does not exist' in error :
734
+ raise Exception
735
+ except Exception as e :
736
+ files = self ._collect_special_files ()
737
+ if any (len (file ) > 1 and 'Is another postmaster already '
738
+ 'running on port' in file [1 ].decode () for
739
+ file in files ):
740
+ print ("Detected an issue with connecting to port {0}. "
741
+ "Trying another port after a 5-second sleep..." .format (self .port ))
742
+ self .port = reserve_port ()
743
+ options = {}
744
+ options ['port' ] = str (self .port )
745
+ self .set_auto_conf (options )
746
+ startup_retries -= 1
747
+ time .sleep (5 )
748
+ continue
749
+
750
+ msg = 'Cannot start node'
751
+ raise_from (StartNodeException (msg , files ), e )
752
+ break
737
753
self ._maybe_start_logger ()
738
754
self .is_started = True
739
755
return self
0 commit comments