Opened 3 months ago

Closed 6 weeks ago

#7446 closed defect (fixed)

x264 init race/corruption

Reported by: lukealonso Owned by: cus
Priority: important Component: avcodec
Version: git-master Keywords: libx264 regression
Cc: cus Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:

I have a program that creates many concurrent instances of x264 via AVCodecContext. Occasionally, I'll get the following output:

x264 [error]: invalid tune '[RANDOM JUNK]'

and avcodec_open2 will fail.

I've attached a stripped down program that reproduces the issue, at least on Ubuntu 16.04.

This appears to happen with all x264 versions, I tried the latest stable commit, and one from several years ago.

This does *NOT* happen with older FFmpeg versions. I git bisected and found that the problem started happening on commit:

[abaa12263e08ae7b2099f00fa4597ae6a86d7a9c] avcodec: Don't lock during open if the codec has threadsafe init]

.... which is not surprising, but not terribly helpful in finding what exactly is happening in X264_init that causes the issue.

Hopefully this is just me being dumb, any pointers would be appreciated.

How to reproduce:

Build enc_test.c:

gcc -o enc_test enc_test.c -lavcodec -lavformat -lavutil -lpthread

Run 1-10 times, with num_threads between 4-32, whatever is appropriate for your machine. Happens more often with higher thread counts. It should happen early on, so ctrl-c and try again if it hasn't happened with in a few seconds.

./enc_test [num_threads]

Attachments (1)

enc_test.c (1.6 KB) - added by lukealonso 3 months ago.
repro

Download all attachments as: .zip

Change History (6)

Changed 3 months ago by lukealonso

repro

comment:1 Changed 3 months ago by cehoyos

  • Keywords libx264 added

Please confirm that the issue is reproducible with current FFmpeg git head and current libx264 git head.

comment:2 Changed 3 months ago by lukealonso

Replying to cehoyos:
Yes, it occurs with ffmpeg git head and libx264 git head.

Last edited 3 months ago by lukealonso (previous) (diff)

comment:3 Changed 3 months ago by cehoyos

  • Keywords regression added
  • Priority changed from normal to important
  • Version changed from unspecified to git-master

Reproducible with both old and current x264.

comment:4 Changed 8 weeks ago by cus

  • Cc cus added
  • Owner set to cus
  • Status changed from new to open

comment:5 Changed 6 weeks ago by cus

  • Resolution set to fixed
  • Status changed from open to closed
Note: See TracTickets for help on using tickets.