libextractor

GNU libextractor
Log | Files | Refs | Submodules | README | LICENSE

commit 49c61d3b5a9e4f6a1b4a3625ffbb0f6a8e88ee0c
parent 38ffdf43d2ce2790131b3d52de8883af18c5e7a3
Author: Christian Grothoff <christian@grothoff.org>
Date:   Thu, 12 Nov 2026 00:08:16 +0100

ipc: give a plugin time to load before the watchdog applies

Any plugin whose libraries loaded slowly the first time lost its
results to the 500 ms watchdog. This killed the GStreamer plugin on
some platforms as the watchdog killed GStreamer before GStreamer could
save its registry...

Diffstat:
MChangeLog | 5+++++
Msrc/main/extractor_ipc_gnu.c | 57++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
Msrc/main/extractor_plugin_main.c | 4++++
3 files changed, 65 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,8 @@ +Thu Nov 12 12:08:16 AM CET 2026 + Give a plugin up to 120 seconds to load before treating it as + blocked. A plugin whose libraries loaded slowly the first time + lost its results. -CG + Wed Nov 11 10:00:00 PM CET 2026 Run out-of-process plugins in the new libextractor-helper program, started with posix_spawn(), instead of in a fork()ed copy of the diff --git a/src/main/extractor_ipc_gnu.c b/src/main/extractor_ipc_gnu.c @@ -125,10 +125,50 @@ struct EXTRACTOR_Channel */ pid_t cpid; + /** + * When the plugin process was started, in milliseconds (see now_ms()). + */ + uint64_t start_time; + + /** + * Set once the plugin process has sent us anything. Until then it may + * still be loading the plugin and its libraries. + */ + int started; + }; /** + * How long a plugin process may take to load its plugin before it is + * treated as blocked, in milliseconds. Loading libraries for the first + * time can take far longer than the 500 ms that LE otherwise tolerates. + * GStreamer, for one, scans all its plugins when its registry does not + * exist yet, which took 55 s right after installing Homebrew's GStreamer + * on macOS. It only saves the registry once the scan completes, so it + * was killed before that and would fail the same way every time. + */ +#define STARTUP_GRACE_MS 120000 + + +/** + * Get a monotonic time stamp. + * + * @return current time in milliseconds since some arbitrary epoch + */ +static uint64_t +now_ms (void) +{ + struct timespec ts; + + if (0 != clock_gettime (CLOCK_MONOTONIC, + &ts)) + return 0; + return ((uint64_t) ts.tv_sec) * 1000 + ts.tv_nsec / 1000000; +} + + +/** * Create a shared memory area. * * @param size size of the shared area @@ -429,6 +469,8 @@ EXTRACTOR_IPC_channel_create_ (struct EXTRACTOR_PluginList *plugin, channel->cpipe_in = p1[1]; channel->cpipe_out = p2[0]; channel->cpid = pid; + channel->start_time = now_ms (); + channel->started = 0; slen = strlen (shm->shm_name) + 1; if (NULL == (init = malloc (sizeof (struct InitMessage) + slen))) { @@ -551,6 +593,8 @@ EXTRACTOR_IPC_channel_recv_ (struct EXTRACTOR_Channel **channels, ssize_t iret; char *ndata; int closed_channel; + int starting_channel; + uint64_t now; FD_ZERO (&to_check); max = -1; @@ -573,6 +617,8 @@ EXTRACTOR_IPC_channel_recv_ (struct EXTRACTOR_Channel **channels, { /* an error or timeout -> something's wrong or all plugins hung up */ closed_channel = 0; + starting_channel = 0; + now = now_ms (); for (i = 0; i<num_channels; i++) { channel = channels[i]; @@ -580,6 +626,13 @@ EXTRACTOR_IPC_channel_recv_ (struct EXTRACTOR_Channel **channels, continue; if (-1 == channel->plugin->seek_request) { + if ( (! channel->started) && + (now - channel->start_time < STARTUP_GRACE_MS) ) + { + /* still loading the plugin, give it more time */ + starting_channel = 1; + continue; + } /* plugin blocked for too long, kill channel */ LOG ("Channel blocked, closing channel to %s\n", channel->plugin->libname); @@ -590,7 +643,8 @@ EXTRACTOR_IPC_channel_recv_ (struct EXTRACTOR_Channel **channels, closed_channel = 1; } } - if (1 == closed_channel) + if ( (1 == closed_channel) || + (1 == starting_channel) ) return 1; /* strange, no channel is to blame, let's die just to be safe */ if ((EINTR != errno) && (0 != errno)) @@ -661,6 +715,7 @@ EXTRACTOR_IPC_channel_recv_ (struct EXTRACTOR_Channel **channels, } else { + channel->started = 1; channel->size = channel->size + iret - ret; memmove (channel->mdata, &channel->mdata[ret], diff --git a/src/main/extractor_plugin_main.c b/src/main/extractor_plugin_main.c @@ -697,6 +697,10 @@ EXTRACTOR_plugin_main_ (struct EXTRACTOR_PluginList *plugin, pc.shm_id = INVALID_SHM_ID; pc.shm = NULL; pc.shm_map_size = 0; + pc.last_alive = 0; + /* tell LE that the plugin is loaded: while it was loading, LE gave us + more time than it gives a plugin that is processing a file */ + send_alive (&pc); process_requests (&pc); LOG ("IPC error; plugin `%s' terminates!\n", plugin->short_libname);