@@ -42,6 +42,7 @@ parray*backup_files_list;
4242static volatile uint32 total_copy_files_increment ;
4343static uint32 total_files_num ;
4444static PGconn * start_stop_connect = NULL ;
45+ static pthread_mutex_t check_stream_mut = PTHREAD_MUTEX_INITIALIZER ;
4546
4647typedef struct
4748{
@@ -170,7 +171,12 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
170171pgBackupGetPath (& current ,path ,lengthof (path ),DATABASE_DIR );
171172join_path_components (dst_backup_path ,path ,"pg_xlog" );
172173dir_create_dir (dst_backup_path ,DIR_PERMISSION );
174+ pthread_mutex_lock (& check_stream_mut );
173175pthread_create (& stream_thread ,NULL , (void * (* )(void * ))StreamLog ,dst_backup_path );
176+ pthread_mutex_lock (& check_stream_mut );
177+ if (conn == NULL )
178+ elog (ERROR ,"I can't continue work because stream connect has failed." );
179+ pthread_mutex_unlock (& check_stream_mut );
174180}
175181
176182if (!from_replica )
@@ -1457,8 +1463,11 @@ StreamLog(void *arg)
14571463if (conn == NULL )
14581464conn = GetConnection ();
14591465if (!conn )
1466+ {
1467+ pthread_mutex_unlock (& check_stream_mut );
14601468/* Error message already written in GetConnection() */
14611469return ;
1470+ }
14621471
14631472if (!CheckServerVersionForStreaming (conn ))
14641473{
@@ -1478,6 +1487,8 @@ StreamLog(void *arg)
14781487if (!RunIdentifySystem (conn ,NULL ,& starttli ,& startpos ,NULL ))
14791488disconnect_and_exit (1 );
14801489
1490+ /* Ok we have normal stream connect and main process can work again */
1491+ pthread_mutex_unlock (& check_stream_mut );
14811492/*
14821493 * We must use startpos as start_lsn from start_backup
14831494 */