search for: allocate_last_error_on_demand

Displaying 4 results from an estimated 4 matches for "allocate_last_error_on_demand".

2023 Mar 08
2
[PATCH libnbd] lib/errors.c: Fix assert fail in exit path in multi-threaded code
...(nbd_get_error ()); abort_option (h); nbd_internal_abort_commands (h, &h->cmds_to_issue); nbd_internal_abort_commands (h, &h->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...
2023 Mar 09
1
[PATCH libnbd v3] lib/errors.c: Fix assert fail in exit path in multi-threaded code
...e (errors_key); > } While I think this fixes the problem with pthread_setspecific crashing, I believe this then opens apps up to the problem hit by libvirt with destructors being run which don't exist in memory. Consider a thread is running that has done something with libnbd which caused allocate_last_error_on_demand() to run, which populates the 'errors_key' data for that thread. This thread is no longer doing anything with libnbd, but the 'errors_key' data remains populated none the less because that's just how thread locals work. Now nothing at all is using libnbd.so, so some thread call...
2023 Mar 08
2
[libnbd PATCH v2] lib/errors.c: Fix assert fail in exit path in multi-threaded code
...delete (errors_key); } @@ -80,6 +83,8 @@ free_errors_key (void *vp) { struct last_error *last_error = vp; + assert (key_use_count > 1); + key_use_count--; free (last_error->error); free (last_error); } @@ -87,16 +92,23 @@ free_errors_key (void *vp) static struct last_error * allocate_last_error_on_demand (void) { - struct last_error *last_error = pthread_getspecific (errors_key); + struct last_error *last_error = NULL; - if (!last_error) { - last_error = calloc (1, sizeof *last_error); - if (last_error) { - int err = pthread_setspecific (errors_key, last_error); - if (err != 0)...
2023 Mar 09
2
[PATCH libnbd v3] lib/errors.c: Fix assert fail in exit path in multi-threaded code
When a highly multi-threaded program such as nbdcopy encounters an error, there is a race condition in the library which can cause an assertion failure and thus a core dump: (1) An error occurs on one of the threads. nbdcopy calls exit(3). (2) In lib/errors.c, the destructor calls pthread_key_delete. (3) Another thread which is still running also encounters an error, and inside libnbd the