search for: errors_key

Displaying 6 results from an estimated 6 matches for "errors_key".

2023 Mar 08
2
[libnbd PATCH v2] lib/errors.c: Fix assert fail in exit path in multi-threaded code
...t;cmds_to_issue); nbd_internal_abort_commands (h, &h->cmds_in_flight); diff --git a/lib/errors.c b/lib/errors.c index 8b77650e..133c752b 100644 --- a/lib/errors.c +++ b/lib/errors.c @@ -34,6 +34,8 @@ struct last_error { /* Thread-local storage of the last error. */ static pthread_key_t errors_key; +/* Zero if errors_key is invalid, else 1 + threads using errors_key. */ +static _Atomic int key_use_count; static void free_errors_key (void *vp) LIBNBD_ATTRIBUTE_NONNULL (1); @@ -51,6 +53,7 @@ errors_key_create (void) strerror (err)); abort (); } + key_use_count++; }...
2023 Mar 09
1
[PATCH libnbd v3] lib/errors.c: Fix assert fail in exit path in multi-threaded code
...k the > pthread_key_t on the exit path. > --- > lib/errors.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/lib/errors.c b/lib/errors.c > index 8b77650ef3..6fbfaacd34 100644 > --- a/lib/errors.c > +++ b/lib/errors.c > @@ -69,7 +69,11 @@ errors_key_destroy (void) > free (last_error->error); > free (last_error); > } > - pthread_key_delete (errors_key); > + > + /* We could do this, but that causes a race condition described here: > + * https://listman.redhat.com/archives/libguestfs/2023-March/031002.html...
2023 Mar 09
2
[PATCH libnbd v3] lib/errors.c: Fix assert fail in exit path in multi-threaded code
...n't any good ways to fix this. I chose to leak the pthread_key_t on the exit path. --- lib/errors.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/errors.c b/lib/errors.c index 8b77650ef3..6fbfaacd34 100644 --- a/lib/errors.c +++ b/lib/errors.c @@ -69,7 +69,11 @@ errors_key_destroy (void) free (last_error->error); free (last_error); } - pthread_key_delete (errors_key); + + /* We could do this, but that causes a race condition described here: + * https://listman.redhat.com/archives/libguestfs/2023-March/031002.html + */ + //pthread_key_delete (er...
2023 Mar 09
1
[PATCH libnbd v3] lib/errors.c: Fix assert fail in exit path in multi-threaded code
This version simply removes the call to pthread_key_destroy. It fixes the problem and allows us to leave the asserts alone so we can still catch real errors. Of course this leaks pthread_key_t in the case where you dlclose() the library. glibc has a limit of 128 thread-specific keys (and the first 32 are somehow "fast" in a way I could quite follow), so that's a thing. Rich.
2023 Mar 08
2
[PATCH libnbd] lib/errors.c: Fix assert fail in exit path in multi-threaded code
...;cmds_in_flight); diff --git a/lib/errors.c b/lib/errors.c index 8b77650ef3..9142a0843e 100644 --- a/lib/errors.c +++ b/lib/errors.c @@ -93,7 +93,10 @@ allocate_last_error_on_demand (void) last_error = calloc (1, sizeof *last_error); if (last_error) { int err = pthread_setspecific (errors_key, last_error); - if (err != 0) { + /* Ignore EINVAL because that can happen in a race with other + * threads when we are exiting. + */ + if (err != 0 && err != EINVAL) { /* This is not supposed to happen (XXX). */ fprintf (stderr, "%s: %s: %s...
2023 Mar 09
1
[PATCH libnbd v4] lib/errors.c: Fix assert fail in exit path in multi-threaded code
...commit: https://gitlab.com/libvirt/libvirt/-/commit/8e44e5593eb9b89fbc0b54fde15f130707a0d81e (a) Use '-z nodelete' to prevent the library from being unloaded on dlclose(). (b) Do not call pthread_key_destroy (thus leaking the key). (c) When threads exit they are still able to call free_errors_key because it is still present in memory. Thanks: Daniel P. Berrang?, Eric Blake --- configure.ac | 9 +++++++++ lib/Makefile.am | 1 + lib/errors.c | 6 +++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index b6d60c3df6..f495926eff 100644 --- a/...