[Libguestfs] nbdkit worker thread shutdown
Nikolaus Rath
nikolaus at rath.org
Thu May 5 11:21:32 UTC 2022
On Thu, 5 May 2022, at 12:04, Laszlo Ersek wrote:
> On 05/05/22 09:59, Nikolaus Rath wrote:
>> Hello,
>>
>> When nbdkit calls a plugin's unload() method, is it guaranteed that all
>> pending requests have been handled (and all worker threads exited)?
>>
>> (I would have expected this to be the case, but I'm getting errors from
>> threads accessing data that my unload() handler frees, so I wanted to
>> confirm my assumption).
>
> From <https://libguestfs.org/nbdkit-plugin.3.html>:
>
> .cleanup
>
> is called once after all connections have been closed, prior to
> unloading the plugin from memory. This is only called if .after_fork
> succeeded earlier (even in cases where nbdkit did not fork but is
> running in the foreground), which makes it a good place to
> gracefully end any background threads.
>
> So I would think you need to either join all threads in .cleanup (at the
> latest), waiting for them to drain any pending work, or cancel them
> (with appropriate cancellation handlers in the background threads).
>
I am taking about the threads started by nbdkit itself. I don't think the plug-in is in a position to join those in the handler - or is it?
Best,
Nikolaus
--
GPG Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F
»Time flies like an arrow, fruit flies like a Banana.«
More information about the Libguestfs
mailing list