@@ -42,6 +42,7 @@ parray *backup_files_list;
42
42
static volatile uint32 total_copy_files_increment ;
43
43
static uint32 total_files_num ;
44
44
static PGconn * start_stop_connect = NULL ;
45
+ static pthread_mutex_t check_stream_mut = PTHREAD_MUTEX_INITIALIZER ;
45
46
46
47
typedef struct
47
48
{
@@ -170,7 +171,12 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
170
171
pgBackupGetPath (& current , path , lengthof (path ), DATABASE_DIR );
171
172
join_path_components (dst_backup_path , path , "pg_xlog" );
172
173
dir_create_dir (dst_backup_path , DIR_PERMISSION );
174
+ pthread_mutex_lock (& check_stream_mut );
173
175
pthread_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 );
174
180
}
175
181
176
182
if (!from_replica )
@@ -1457,8 +1463,11 @@ StreamLog(void *arg)
1457
1463
if (conn == NULL )
1458
1464
conn = GetConnection ();
1459
1465
if (!conn )
1466
+ {
1467
+ pthread_mutex_unlock (& check_stream_mut );
1460
1468
/* Error message already written in GetConnection() */
1461
1469
return ;
1470
+ }
1462
1471
1463
1472
if (!CheckServerVersionForStreaming (conn ))
1464
1473
{
@@ -1478,6 +1487,8 @@ StreamLog(void *arg)
1478
1487
if (!RunIdentifySystem (conn , NULL , & starttli , & startpos , NULL ))
1479
1488
disconnect_and_exit (1 );
1480
1489
1490
+ /* Ok we have normal stream connect and main process can work again */
1491
+ pthread_mutex_unlock (& check_stream_mut );
1481
1492
/*
1482
1493
* We must use startpos as start_lsn from start_backup
1483
1494
*/
0 commit comments