@smcv
Copy link
Contributor

smcv commented Feb 26, 2022

Relevant package versions:

libappstream4:amd64	0.15.2-2
libglib2.0-0:amd64	2.70.4-1

with flatpak git HEAD, on Debian unstable. (Note that flatpak 1.12.x used libappstream-glib, but git HEAD has switched to libappstream.)

Steps to reproduce: run the Flatpak test suite

Expected result: tests succeed

Actual result: several tests fail with this assertion failure in libappstream:

(flatpak search:260854): GLib-CRITICAL **: 14:05:04.766: g_once_init_leave: assertion 'g_atomic_pointer_get (value_location) == 0' failed
.../tests/test-repo.sh: line 109: 260854 Trace/breakpoint trap   (core dumped) ${FLATPAK} search Hello > search-results

Backtrace:

#0  g_logv
    (log_domain=0x7f5e3982300e "GLib", log_level=G_LOG_LEVEL_CRITICAL, format=<optimized out>, args=<optimized out>)
    at ../../../glib/gmessages.c:1417
#1  0x00007f5e397d678f in g_log (log_domain=<optimized out>, log_level=<optimized out>, format=<optimized out>)
    at ../../../glib/gmessages.c:1455
#2  0x00007f5e3a1af451 in as_component_search_matches
    (cpt=cpt@entry=0x55cc24af1200 [AsComponent], term=term@entry=0x7ffc50fcf003 "org.test.Hello")
    at ../src/as-component.c:2942
#3  0x000055cc22a57ddd in flatpak_builtin_search
    (argc=<optimized out>, argv=<optimized out>, cancellable=<optimized out>, error=<optimized out>)
    at /home/smcv/src/flatpak/app/flatpak-builtins-search.c:296
#4  0x000055cc22a2e0e6 in flatpak_run (argc=<optimized out>, argc@entry=3, argv=<optimized out>, 
    argv@entry=0x7ffc50fce198, res_error=res_error@entry=0x7ffc50fce078)
    at /home/smcv/src/flatpak/app/flatpak-main.c:854
#5  0x000055cc22a2ee68 in main (argc=3, argv=0x7ffc50fce198) at /home/smcv/src/flatpak/app/flatpak-main.c:959

This seems to be a bug in libappstream rather than a bug in Flatpak. The assertion failure is here:

	/* ensure the token cache is created */
	if (g_once_init_enter (&priv->token_cache_valid)) {
		as_component_create_token_cache (cpt);
		g_once_init_leave (&priv->token_cache_valid, TRUE);      <-- here
	}

because both as_component_create_token_cache() and the g_once_init_enter()/g_once_init_leave() pair are trying to be responsible for writing to priv->token_cache_valid:

void
as_component_create_token_cache (AsComponent *cpt)
{
	AsComponentPrivate *priv = GET_PRIVATE (cpt);
	guint flags;

	if (priv->token_cache_valid)
		return;

        ... implementation here ...

	priv->token_cache_valid = TRUE;
}