Skip to content

Commit

Permalink
Fix data race when stop stream during connection (obsproject#184)
Browse files Browse the repository at this point in the history
Fix a data race when user manually stopped stream during connecting to a RTMP server.

This is caused by a data race in `obs_output_destroy` method, which call `rtmp_stream_destroy` method before output became active. In such case, the `rtmp_stream_destroy` method will detach `end_data_capture` thread, thus it will result in a potential crash. In order to avoid this, the thread which destroys output should wait till `end_data_capture` will be finished.
  • Loading branch information
borzun committed Apr 30, 2020
1 parent 873538c commit 020070b
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions libobs/obs-output.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,15 @@ void obs_output_destroy(obs_output_t *output)
if (output->context.data) {
output->info.destroy(output->context.data);
output->context.data = NULL;

// In case when output has started connecting, but haven't started
// capturing data (i.e. not active), the info `destroy` call can
// switch output to active state - in this case it is needed to wait till
// the `end_data_capture_thread` will finish.
// Otherwise we might run into a data race
if (data_capture_ending(output))
pthread_join(output->end_data_capture_thread,
NULL);
}

free_packets(output);
Expand Down

0 comments on commit 020070b

Please sign in to comment.