Skip to content

Commit

Permalink
Retry loop with backoff in test_server_start
Browse files Browse the repository at this point in the history
Signed-off-by: Cole Miller <[email protected]>
  • Loading branch information
cole-miller committed Feb 22, 2024
1 parent d408763 commit ba76637
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
3 changes: 2 additions & 1 deletion include/dqlite.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ DQLITE_API DQLITE_EXPERIMENTAL void dqlite_server_destroy(
enum {
DQLITE_ERROR = 1, /* Generic error */
DQLITE_MISUSE, /* Library used incorrectly */
DQLITE_NOMEM /* A malloc() failed */
DQLITE_NOMEM, /* A malloc() failed */
DQLITE_AGAIN /* Retryable error */
};

/**
Expand Down
3 changes: 2 additions & 1 deletion src/raft.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ enum {
RAFT_INVALID, /* Invalid parameter */
RAFT_UNAUTHORIZED, /* No access to a resource */
RAFT_NOSPACE, /* Not enough space on disk */
RAFT_TOOMANY /* Some system or raft limit was hit */
RAFT_TOOMANY, /* Some system or raft limit was hit */
RAFT_AGAIN /* Retryable error */
};

/**
Expand Down
7 changes: 5 additions & 2 deletions src/raft/uv_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -774,8 +774,11 @@ static int probeAsyncIO(int fd, size_t size, bool *ok, char *errmsg)
rv = UvOsIoSetup(1, &ctx);
if (rv != 0) {
UvOsErrMsg(errmsg, "io_setup", rv);
/* UNTESTED: in practice this should fail only with ENOMEM */
return RAFT_IOERR;
if (rv == -EAGAIN) {
return RAFT_AGAIN;
} else {
return RAFT_IOERR;
}
}

/* Allocate the write buffer */
Expand Down
2 changes: 1 addition & 1 deletion src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ int dqlite__init(struct dqlite_node *d,
if (rv != 0) {
snprintf(d->errmsg, DQLITE_ERRMSG_BUF_SIZE, "raft_init(): %s",
raft_errmsg(&d->raft));
return DQLITE_ERROR;
return (rv == RAFT_AGAIN) ? DQLITE_AGAIN : DQLITE_ERROR;
}
/* TODO: expose these values through some API */
raft_set_election_timeout(&d->raft, 3000);
Expand Down
13 changes: 12 additions & 1 deletion test/lib/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,18 @@ void test_server_start(struct test_server *s, const MunitParameter params[])
{
int rv;

rv = dqlite_node_create(s->id, s->address, s->dir, &s->dqlite);
struct timespec ts = {.tv_sec = 0, .tv_nsec = 1000000};
do {
rv = dqlite_node_create(s->id, s->address, s->dir, &s->dqlite);
if (rv != 0) {
dqlite_node_destroy(s->dqlite);
}
if (rv != DQLITE_AGAIN) {
break;
}
nanosleep(&ts, NULL);
ts.tv_nsec *= 2;
} while (ts.tv_nsec < 1000000000);
munit_assert_int(rv, ==, 0);

rv = dqlite_node_set_bind_address(s->dqlite, s->address);
Expand Down

0 comments on commit ba76637

Please sign in to comment.