Hi, On Mon, 2019-11-18 at 15:33 -0500, Frank Ch. Eigler wrote: > > > > Do you know how other libraries that use libcurl deal with this? > > > > > > I looked over some other libcurl users in fedora. Some don't worry > > > about the issue at all, relying on implicit initialization, which is > > > only safe if single-threaded. Others (libvirtd) do an explicitly > > > invoked initialization function, which is also only safe if invoked > > > from a single-threaded context. > > > > > > I think actually our way here, running the init function from the > > > shared library constructor, is about the best possible. As long as > > > the ld.so process is done as normal, it should be fine. Programs that > > > use the elfutils trick of manual dlopen'ing libdebuginfod.so should do > > > so only if they are single-threaded. > > > > But they cannot really control that... Since they might not know (and > > really shouldn't care) that libdw lazily tries to dlopen > > libdebuginfod.so which then pulls in libcurl and calls that global init > > function... > > > > Could we do try to do the dlopen and global curl initialization from > > libdw _init, or a ctor, to make sure it is done as early as possible? > > Doing a redundant initialization later is not a problem; there is a > counter in there. The problematic case would be > - a multithreaded application > - loading debuginfod.so multiply concurrently somehow > - and calling the solib ctor concurrently somehow > - and all of this concurrently enough to defeat libcurl's init-counter > > IMHO, not worth worrying about. Someday libcurl will do the right > thing (tm) and plop this initialization into their solib ctor.
I do worry about this because any multi-threaded app that uses libdw.so might cause trouble because we dlopen libdebuginfod.so lazily and then it will call curl_global_init () which explicitly says: This function is not thread safe. You must not call it when any other thread in the program (i.e. a thread sharing the same memory) is running. This doesn't just mean no other thread that is using libcurl. Because curl_global_init calls functions of other libraries that are similarly thread unsafe, it could conflict with any other thread that uses these other libraries. That is why I think doing the dlopen of libdebuginfod.so eagerly from a libdw.so constructor function or _init might be necessary to make sure no other threads are running yet. > > > > I was more thinking zero == infinity (no timeout). > > > > > > An unset environment variable should do that. > > > > Are you sure? If DEBUGINFOD_TIMEOUT isn't set, then it seems it > > defaults to 5 seconds: > > > > /* Timeout for debuginfods, in seconds. > > This env var must be set for debuginfod-client to run. */ > > static const char *server_timeout_envvar = > > DEBUGINFOD_TIMEOUT_ENV_VAR; > > static int server_timeout = 5; > > [...] > > > > if (getenv(server_timeout_envvar)) > > server_timeout = atoi (getenv(server_timeout_envvar)); > > OK, hm, we could make an -empty- but set environment variable mean > 'infinity'. Then again, a user can also say =99999. Yes. In this case even setting it to 600 probably feels like forever anyway since someone is waiting on the file... :) Cheers, Mark