Skip to content

Commit 8b0157f

Browse files
authored
Merge pull request #4345 from chu11/issue4343_future_wait_for_errno
libflux: return better errno in future wait path
2 parents f614beb + d444fcd commit 8b0157f

File tree

5 files changed

+18
-8
lines changed

5 files changed

+18
-8
lines changed

doc/man3/flux_future_get.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ ETIMEDOUT
129129
A timeout passed to ``flux_future_wait_for()`` expired before the future
130130
was fulfilled.
131131

132+
EDEADLOCK
133+
``flux_future_wait_for()`` would likely deadlock due to an
134+
improperly initialized future.
132135

133136
RESOURCES
134137
=========

doc/test/spell.en.pws

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,3 +626,4 @@ num
626626
gc
627627
tgz
628628
tmpfiles
629+
EDEADLOCK

src/common/libflux/future.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -481,11 +481,17 @@ int flux_future_wait_for (flux_future_t *f, double timeout)
481481
f->now->running = false;
482482
}
483483
if (!future_is_ready (f)) {
484-
/* Typically this error should be "impossible", but can occur
485-
* if the future does not get initialized properly to use the
486-
* now reactor.
484+
/* This block of code is reached b/c flux_reactor_run() on the
485+
* "now" reactor returned >= 0 AND the future was
486+
* not fulfilled, e.g.
487+
* - no init callback was registered when future was created
488+
* - the init callback didn't register any watchers
489+
* - the registered watchers stopped themselves or called
490+
* flux_reactor_stop() without fulfilling the future.
491+
* Return EDEADLOCK indicating that the future cannot be
492+
* fulfilled.
487493
*/
488-
errno = EINVAL;
494+
errno = EDEADLOCK;
489495
return -1;
490496
}
491497
return 0;

src/common/libflux/test/future.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ void test_simple (void)
122122
ok (!flux_future_is_ready (f),
123123
"flux_future_is_ready returns false");
124124
errno = 0;
125-
ok (flux_future_wait_for (f, -1.0) < 0 && errno == EINVAL,
126-
"flux_future_wait_for fails with EINVAL with timeout < 0");
125+
ok (flux_future_wait_for (f, -1.0) < 0 && errno == EDEADLOCK,
126+
"flux_future_wait_for fails with EDEADLOCK with timeout < 0");
127127
ok (!flux_future_is_ready (f),
128128
"flux_future_is_ready returns false");
129129
errno = 0;

src/common/libkvs/test/kvs_checkpoint.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ void errors (void)
5050

5151
errno = 0;
5252
ok (kvs_checkpoint_lookup_get_rootref (f, &rootref) < 0
53-
&& errno == EINVAL,
53+
&& errno == EDEADLOCK,
5454
"kvs_checkpoint_lookup_get_rootref fails on unfulfilled future");
5555

5656
errno = 0;
5757
double timestamp;
5858
ok (kvs_checkpoint_lookup_get_timestamp (f, &timestamp) < 0
59-
&& errno == EINVAL,
59+
&& errno == EDEADLOCK,
6060
"kvs_checkpoint_lookup_get_timestamp fails on unfulfilled future");
6161

6262
flux_future_destroy (f);

0 commit comments

Comments
 (0)