Opened 9 months ago

Last modified 8 months ago

#9206 new defect

ffmpeg goes into interruptible sleep because of temporary network problem and can not recover

Reported by: Jarno Suni Owned by:
Priority: normal Component: undetermined
Version: unspecified Keywords: http
Cc: Jarno Suni Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:
How to reproduce:

% ffmpeg -i http://stream.wappuradio.fi/wappuradio.opus -c copy output.opus

I had some temporary problem in internet connection or my the router, and probably due to that ffmpeg was waiting for some data to arrive. When internet connection started to work again, ffmpeg did not continue recording but remained in interuptible sleep state. I killed the process by SIGINT. I will tell you later, if I can reproduce the issue, but I think the bug and fix can be found by analyzing the code.

Expected behavior:
Option 1:
ffmpeg should exit with non-zero error code
Option 2: ffmpeg should be able to continue recording automatically when possible even if some part of the recording was missed. ffmpeg should somehow notify caller that some part was missed.

NOTE: There has been some breaks in the input stream before, but then ffmpeg exited so I can relaunch it automatically periodically, if needed.

Maybe there are some ffmpeg options I can use the make it work better for me in these kind of problem cases?

Patches should be submitted to the ffmpeg-devel mailing list and not this bug tracker.

Change History (11)

comment:1 by Carl Eugen Hoyos, 9 months ago

Keywords: http added; interuptible sleep removed
Version: 3.4.8unspecified

Please test current FFmpeg git head and provide the command line you tested together with the complete, uncut console output to make this a valid ticket.

comment:2 by Jarno Suni, 9 months ago

Please give me instructions on building such ffmpeg and how to install and uninstall that in Ubuntu 18.04 or 20.04. Do you have an idea on how to test that? Should I wait that my internet connection fail or what? Please make reasonable requests for valid tickets.

comment:3 by Nicolas George, 9 months ago

Instructions to build FFmpeg on Ubuntu are already easy to find.

You can simulate a failure of your Internet connection by unplugging the cable or turning off the wifi controller for a few minutes.

In this instance, it seems to me that the http component neglects to allow to set a timeout on the underlying tcp component, but it needs checking.

comment:4 by Jarno Suni, 9 months ago

I could reproduce it at least sometimes with ffmpeg version 4.2.4. I waited 4 minutes before reconnecting the cable. If I waited just short time it could continue recording. Maybe later I am able to test by current git HEAD and maybe you can tell, if there have been relevant commits. I might test 4.3.2 even sooner. And maybe someone else can test sooner by the git HEAD.

comment:5 by Jarno Suni, 9 months ago

% sudo strace -p <pid_of_ffmpeg>

keeps telling

strace: Process 9747 attached
restart_syscall(<... resuming interrupted read ...>) = 0
poll([{fd=3, events=POLLIN}], 1, 100) = 0 (Timeout)
poll([{fd=3, events=POLLIN}], 1, 100) = 0 (Timeout)
poll([{fd=3, events=POLLIN}], 1, 100) = 0 (Timeout)
.
.
.

comment:6 by Nicolas George, 9 months ago

Why are you using sudo for that, it is a terrible idea?

strace does not tell you what software logic between each poll() call is.

comment:7 by Jarno Suni, 9 months ago

I saw https://unix.stackexchange.com/a/47259/111181
The command gave "strace: Could not attach to process. If your uid matches the uid of the target process, check the setting of /proc/sys/kernel/yama/ptrace_scope, or try again as the root user. For more details, see /etc/sysctl.d/10-ptrace.conf: Operation not permitted
strace: attach: ptrace(PTRACE_SEIZE, 13870): Operation not permitted" if I ran it as normal user. Why it is terrible idea to use sudo?

comment:8 by Jarno Suni, 9 months ago

Also version 4.3.2 is affected.

in reply to:  3 comment:9 by Jarno Suni, 9 months ago

Replying to Nicolas George:

Instructions to build FFmpeg on Ubuntu are already easy to find.

I found the instructions, but building according to those instructions fails in Ubuntu 20.04.

comment:10 by Jarno Suni, 9 months ago

It took me few hours to get the required ffmpeg binary (with no extra codecs; not by the instructions you told me to search for), and then few minutes to do the test. I could not use the original stream because it is no more available. I happened to find one local radio stream that uses a supported open format.

$ ./ffmpeg -i https://stream.alandsradio.ax/stream.ogg -c copy /data/test.ogg
ffmpeg version N-102441-ge2301feabc Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 9 (Ubuntu 9.3.0-17ubuntu1~20.04)
  configuration: --enable-gnutls
  libavutil      57.  0.100 / 57.  0.100
  libavcodec     59.  0.100 / 59.  0.100
  libavformat    59.  0.101 / 59.  0.101
  libavdevice    59.  0.100 / 59.  0.100
  libavfilter     8.  0.101 /  8.  0.101
  libswscale      6.  0.100 /  6.  0.100
  libswresample   4.  0.100 /  4.  0.100
Input #0, ogg, from 'https://stream.alandsradio.ax/stream.ogg':
  Metadata:
    icy-br          : 128
    icy-name        : no name
    icy-pub         : 0
  Duration: N/A, start: 665253.260000, bitrate: N/A
  Stream #0:0: Audio: opus, 48000 Hz, stereo, fltp
    Metadata:
      ENCODER         : 0.1.15
Output #0, ogg, to '/data/test.ogg':
  Metadata:
    icy-br          : 128
    icy-name        : no name
    icy-pub         : 0
    encoder         : Lavf59.0.101
  Stream #0:0: Audio: opus, 48000 Hz, stereo, fltp
    Metadata:
      ENCODER         : 0.1.15
      icy-br          : 128
      icy-name        : no name
      icy-pub         : 0
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
size=     206kB time=00:00:14.03 bitrate= 120.1kbits/s speed=1.36x

I unplugged ethernet cable for few minutes and reconnected. ffmpeg could neither proceed nor quit; it did not react to q, so I pressed Ctrl-C to interrupt to get this:

^Chttps://stream.alandsradio.ax/stream.ogg: Input/output error.36x    
Error writing trailer of /data/test.ogg: Immediate exit requested
size=     227kB time=00:00:14.33 bitrate= 129.8kbits/s speed=0.0218x    
video:0kB audio:225kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.861014%
Exiting normally, received signal 2.

comment:11 by ZhenWang, 8 months ago

I ran into the same problem.


poll([{fd=3, events=POLLIN}], 1, 100)   = 1 ([{fd=3, revents=POLLIN}])
recvfrom(3, "\0\5\300", 3, 0, NULL, NULL) = 3
poll([{fd=3, events=POLLIN}], 1, 100)   = 1 ([{fd=3, revents=POLLIN}])
recvfrom(3, "\200`V\322e@k\216\315\v\371_|\1\255\372\376\31R\364;\221\2323y\275\r\323\262\231.\324"..., 1472, 0, NULL, NULL) = 1472
poll([{fd=3, events=POLLIN}], 1, 100)   = 1 ([{fd=3, revents=POLLIN}])
recvfrom(3, "$", 1, 0, NULL, NULL)      = 1
poll([{fd=3, events=POLLIN}], 1, 100)   = 1 ([{fd=3, revents=POLLIN}])
recvfrom(3, "\0\5\300", 3, 0, NULL, NULL) = 3
poll([{fd=3, events=POLLIN}], 1, 100)   = 1 ([{fd=3, revents=POLLIN}])
recvfrom(3, "\200`V\323e@k\216\315\v\371_|\1\\\303\306\22\247\311\313\236Q\0179\333y\37\32X<\212"..., 1472, 0, NULL, NULL) = 1472
poll([{fd=3, events=POLLIN}], 1, 100)   = 1 ([{fd=3, revents=POLLIN}])
recvfrom(3, "$", 1, 0, NULL, NULL)      = 1
poll([{fd=3, events=POLLIN}], 1, 100)   = 1 ([{fd=3, revents=POLLIN}])
recvfrom(3, "\0\2\30", 3, 0, NULL, NULL) = 3
poll([{fd=3, events=POLLIN}], 1, 100)   = 1 ([{fd=3, revents=POLLIN}])
recvfrom(3, "\200\340V\324e@k\216\315\v\371_|A\206\230Q[\274\0k\314\235W\206\201\2554\252)D\326"..., 536, 0, NULL, NULL) = 536
poll([{fd=3, events=POLLIN}], 1, 100)   = 0 (Timeout)
poll([{fd=3, events=POLLIN}], 1, 100)   = 0 (Timeout)
poll([{fd=3, events=POLLIN}], 1, 100)   = 0 (Timeout)
poll([{fd=3, events=POLLIN}], 1, 100)   = 0 (Timeout)
poll([{fd=3, events=POLLIN}], 1, 100)   = 0 (Timeout)
poll([{fd=3, events=POLLIN}], 1, 100)   = 0 (Timeout)
poll([{fd=3, events=POLLIN}], 1, 100)   = 0 (Timeout)
poll([{fd=3, events=POLLIN}], 1, 100)   = 0 (Timeout)
poll([{fd=3, events=POLLIN}], 1, 100)   = 0 (Timeout)
poll([{fd=3, events=POLLIN}], 1, 100)   = 0 (Timeout)


Note: See TracTickets for help on using tickets.