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).
.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'm saying "at the latest" because in the vddk plugin, for example,
pthread_join is called earlier: in .close. I guess that depends on
whether your background thread(s) work at the connection level, or
higher than that (at plugin level).
Thanks
Laszlo