[packagekit] pk_backend_finished race issue

Richard Hughes hughsient at gmail.com
Thu Sep 13 12:23:02 PDT 2007

On 13/09/2007, Grzegorz Dąbrowski <gdx at o2.pl> wrote:
> On Thu, 2007-09-13 at 20:07 +0200, Tom Parker wrote:
> > I think I'm hitting a race issue in pk_backend_finished, like Grzegorz
> > was seeing in the box backend, but this time with the apt backend.
> >
> > Running a search that you know only returns one result repeatedly
> > eventually (3-4 repeats tops) causes a crash with a crappy stacktrace,
> > even with all the debug symbols on and "G_DEBUG=fatal_criticals
> > G_SLICE=debug-blocks" set in the environment. Adding in a short delay
> > (.5s) before the pk_backend_finished removes the problem (>8 repeats,
> > all ok).
> >
> > Richard? Anything more you can do to help this?
> The crash is when thread is still running and g_module_close is called.
> The problem is, we cannot really detect when thread ends. I was trying
> to use g_async_queue_push in thread and g_async_queue_pop in the backend
> module, but it doesn't help. I've found one solution, but I think it's
> ugly:
> 1. At the end of thread set a global variable with exit code.
> 2. In a thread's caller wait for a valid exit code, e.g. while
> (exit_code < 0) { sleep(something); }...
> 3. pk_backend_finished( with_valid_exit_code )

That would make sense. The thread calls pk_backend_finished and we
then try to unload the module as the thread is still running.

Surely we can fix this simply by just causing the unload to wait for
say one second (after getting ::finished) in the backend code, surely
enough time to finish the thread and exit.

If you change the g_timeout_add (500, pk_backend_finished_idle, backend)
 in pk_backend_finished() to g_timeout_add (500,
pk_backend_finished_idle, backend); does the crash go away?


More information about the PackageKit mailing list