@@ -38,12 +38,10 @@ void *report(void *c) {
3838 size_t cur_time , cur_bytes , cur_rows , total_time , total_speed_mbps , total_speed_rps ;
3939 size_t inc_bytes , inc_rows , inc_time , inc_speed_mbps , inc_speed_rps ;
4040
41- pthread_detach (pthread_self ());
42-
4341 flb_plg_info (ctx -> ins , "Start progress reporter with interval %d" , ctx -> log_progress_interval );
4442
45- while (ctx -> log_progress_interval > 0 ) {
46- sleep (ctx -> log_progress_interval );
43+ while (ctx -> reporter -> running && ctx -> log_progress_interval > 0 ) {
44+ flb_time_msleep (ctx -> log_progress_interval * 1000 );
4745
4846 cur_time = cfl_time_now () / 1000000000L ;
4947 cur_bytes = ctx -> reporter -> total_bytes ;
@@ -100,15 +98,23 @@ struct flb_out_doris *flb_doris_conf_create(struct flb_output_instance *ins,
10098 /* Validate */
10199 if (!ctx -> endpoint_type || (strcasecmp (ctx -> endpoint_type , "fe" ) != 0 && strcasecmp (ctx -> endpoint_type , "be" ) != 0 )) {
102100 flb_plg_error (ins , "endpoint_type is invalid" );
101+ flb_free (ctx );
102+ return NULL ;
103103 }
104104 if (!ctx -> user ) {
105105 flb_plg_error (ins , "user is not set" );
106+ flb_free (ctx );
107+ return NULL ;
106108 }
107109 if (!ctx -> database ) {
108110 flb_plg_error (ins , "database is not set" );
111+ flb_free (ctx );
112+ return NULL ;
109113 }
110114 if (!ctx -> table ) {
111115 flb_plg_error (ins , "table is not set" );
116+ flb_free (ctx );
117+ return NULL ;
112118 }
113119
114120 /* Check if SSL/TLS is enabled */
@@ -179,12 +185,13 @@ struct flb_out_doris *flb_doris_conf_create(struct flb_output_instance *ins,
179185 flb_doris_conf_destroy (ctx );
180186 return NULL ;
181187 }
188+ reporter -> running = 1 ;
182189 reporter -> total_bytes = 0 ;
183190 reporter -> total_rows = 0 ;
184191 reporter -> failed_rows = 0 ;
185192 ctx -> reporter = reporter ;
186193
187- if (pthread_create (& ctx -> reporter_thread , NULL , report , (void * ) ctx )) {
194+ if (pthread_create (& ctx -> reporter_thread , NULL , report , (void * ) ctx )) {
188195 flb_plg_error (ins , "failed to create progress reporter" );
189196 flb_doris_conf_destroy (ctx );
190197 return NULL ;
@@ -205,7 +212,8 @@ void flb_doris_conf_destroy(struct flb_out_doris *ctx)
205212 }
206213
207214 if (ctx -> reporter ) {
208- pthread_cancel (ctx -> reporter_thread );
215+ ctx -> reporter -> running = 0 ;
216+ pthread_join (ctx -> reporter_thread , NULL );
209217 flb_free (ctx -> reporter );
210218 }
211219
0 commit comments