Cherry picked antoviaque's fix on syncdb hang