Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@vrabaud
Copy link
Contributor

@vrabaud vrabaud commented Apr 16, 2024

initLogger_ does not check if the logger has been initizalized before and it might initialize it several times from different threads, racing with other threads that are logging.

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work

if(!threadSafe)
lock.lock();
static InternalFFMpegRegister instance;
initLogger_(); // update logger setup unconditionally (GStreamer's libav plugin may override these settings)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I take a look on the comment.

It comes from this commit: 7baf2e8

which commit message says "repair FFmpeg logger settings on each .open() call"

@mshabunin Do you remember which reproducer we had for this case?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mshabunin Do you remember which reproducer we had for this case?

No, I don't 🙁
PR was #19661

@vrabaud
Copy link
Contributor Author

vrabaud commented Apr 16, 2024

FYI, the stack trace we have is (line numbers might be off by a few units; if needed I can get the exact code references):

  Write of size 4 at 0x556a7df5e66c by thread T152 (mutexes: write M0):
    #0 av_log_set_level third_party/ffmpeg/src/libavutil/log.c:387:18 
    #1 initLogger_ third_party/OpenCV/public/modules/./videoio/src/cap_ffmpeg_impl.hpp:950:13
    #2 InternalFFMpegRegister::init(bool) third_party/OpenCV/public/modules/./videoio/src/cap_ffmpeg_impl.hpp:930:9
    #3 CvVideoWriter_FFMPEG::open(char const*, int, double, int, int, cv::VideoWriterParameters const&) third_party/OpenCV/public/modules/./videoio/src/cap_ffmpeg_impl.hpp:2779:5
    #4 cvCreateVideoWriterWithParams_FFMPEG third_party/OpenCV/public/modules/./videoio/src/cap_ffmpeg_impl.hpp:3344:17
...
  Previous read of size 4 at 0x556a7df5e66c by thread T190 (mutexes: write M1):
    #0 av_log_default_callback third_party/ffmpeg/src/libavutil/log.c:316:17
    #1 av_vlog third_party/ffmpeg/src/libavutil/log.c:377:9
    #2 av_log third_party/ffmpeg/src/libavutil/log.c:369:5
    #3 h264_parse_nal_header third_party/ffmpeg/src/libavcodec/h2645_parse.c:324:5 

vrabaud added 3 commits April 17, 2024 14:31
initLogger_ does not check if the logger has been initizalized
before and it might initialize it several times from different
threads, racing with other threads that are logging.
@asmorkalov asmorkalov merged commit c317a3e into opencv:4.x Apr 17, 2024
@vrabaud vrabaud deleted the ffmpeg branch April 17, 2024 14:03
@asmorkalov asmorkalov mentioned this pull request Apr 19, 2024
klatism pushed a commit to klatism/opencv that referenced this pull request May 17, 2024
Fix race condition in InternalFFMpegRegister initialization. opencv#25419

initLogger_ does not check if the logger has been initizalized before and it might initialize it several times from different threads, racing with other threads that are logging.

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants