Skip to content

Commit

Permalink
Properly update the binlog linked list pointers.
Browse files Browse the repository at this point in the history
Code in this file assumes that newest_binlog is always correct, so when
there is no binlog at all, we must set newest_binlog to NULL.

Closes gh-44.
  • Loading branch information
kr committed Jun 24, 2010
1 parent 349a98c commit 70b63d5
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
5 changes: 4 additions & 1 deletion binlog.c
Expand Up @@ -111,6 +111,10 @@ binlog_remove_oldest()

oldest_binlog = b->next;

if (newest_binlog == b) {
newest_binlog = b->next; /* == 0 */
}

unlink(b->path);
free(b);
}
Expand Down Expand Up @@ -778,7 +782,6 @@ binlog_init(job binlog_jobs)

}


/* Set up for writing out new jobs */
n = ensure_free_space(1);
if (!n) return twarnx("error making first writable binlog");
Expand Down
46 changes: 46 additions & 0 deletions sh-tests/binlog-empty-oom.sh
@@ -0,0 +1,46 @@
#!/usr/bin/env bash

. "$SRCDIR/sh-tests/common.functions"

server=localhost
tmpdir="$TMPDIR"
size=601
test -z "$tmpdir" && tmpdir=/tmp
out1="${tmpdir}/bnch$$.1"
logdir="${tmpdir}/bnch$$.d"
nc="$SRCDIR/sh-tests/netcat.py"

cleanup() {
killbeanstalkd
rm -rf "$logdir" "$out1"
}

catch() {
echo '' Interrupted
exit 3
}

trap cleanup EXIT
trap catch HUP INT QUIT TERM

if [ ! -x ./beanstalkd ]; then
echo "Executable ./beanstalkd not found; do you need to compile first?"
exit 2
fi

start_beanstalkd $logdir

killbeanstalkd -9

start_beanstalkd $logdir

$nc $server $port <<EOF > "$out1"
put 0 0 0 0
quit
EOF

diff - "$out1" <<EOF
INSERTED 1
EOF

0 comments on commit 70b63d5

Please sign in to comment.