Skip to content

Commit d85ff44

Browse files
minkikim89dormando
authored andcommitted
restart: add error handling when a tag is not found in a metadata file.
1 parent 266d582 commit d85ff44

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

restart.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ static int restart_check(const char *file) {
8282
restart_cb_ctx ctx;
8383

8484
ctx.f = f;
85+
ctx.cb = NULL;
8586
ctx.line = NULL;
8687
ctx.done = false;
8788
if (restart_get_kv(&ctx, NULL, NULL) != RESTART_DONE) {
@@ -91,6 +92,10 @@ static int restart_check(const char *file) {
9192
// TODO: this should probably just return -1 and skip the reuse.
9293
abort();
9394
}
95+
if (ctx.cb == NULL) {
96+
fprintf(stderr, "[restart] Failed to read a tag from metadata file\n");
97+
abort();
98+
}
9499

95100
// loop call the callback, check result code.
96101
bool failed = false;

t/restart.t

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ use MemcachedTest;
1212
# /dev/shm.
1313
my $mem_path = "/tmp/mc_restart.$$";
1414

15+
# read a invalid metadata file
16+
{
17+
my $meta_path = "$mem_path.meta";
18+
open(my $f, "> $meta_path") || die("Can't open a metadata file.");
19+
eval { new_memcached("-e $mem_path"); };
20+
unlink($meta_path);
21+
ok($@, "Died with an empty metadata file");
22+
}
23+
1524
my $server = new_memcached("-m 128 -e $mem_path -I 2m");
1625
my $sock = $server->sock;
1726

0 commit comments

Comments
 (0)