Skip to content

Commit

Permalink
Fix od_rules_group_checker_run (light verion) (#695)
Browse files Browse the repository at this point in the history
* Fix od_rules_group_checker_run

* Fix memleak when group checker fail to check

* Add test with falling postgres
  • Loading branch information
visill authored Oct 3, 2024
1 parent 2615441 commit 802396d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docker/group/config.conf
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,5 @@ enable_online_restart yes
bindwith_reuseport yes

stats_interval 60

group_checker_interval 500
pid_file "/var/run/odyssey.pid"
19 changes: 18 additions & 1 deletion docker/group/test_group.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,21 @@ psql -h ip4-localhost -p 6432 -U group_user7 -c "SELECT 1" group_db >/dev/null 2
exit 1
}

ody-stop
sudo -u postgres /usr/lib/postgresql/14/bin/pg_ctl -D /var/lib/postgresql/14/repl/ -o '-p 5433' stop
sudo -u postgres /usr/lib/postgresql/14/bin/pg_ctl -D /var/lib/postgresql/14/main/ stop
sleep 2
sudo -u postgres /usr/lib/postgresql/14/bin/pg_ctl -D /var/lib/postgresql/14/main/ start
sudo -u postgres /usr/lib/postgresql/14/bin/pg_ctl -D /var/lib/postgresql/14/repl/ -o '-p 5433' start
psql -h ip4-localhost -p 6432 -U group_user7 -c "SELECT 1" group_db >/dev/null 2>&1 && {
echo "Break by falling postgres"

cat /var/log/odyssey.log
echo "
"
cat /var/log/postgresql/postgresql-14-main.log

exit 1
}

ody-stop
24 changes: 23 additions & 1 deletion sources/rules.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ void od_rules_group_checker_run(void *arg)
continue;
}
}

/* TODO: remove this loop (always works once)*/
for (int retry = 0; retry < group->check_retry; ++retry) {
if (od_backend_query_send(
server, "group_checker", group->group_query,
Expand All @@ -295,6 +295,11 @@ void od_rules_group_checker_run(void *arg)
"read error: %s",
od_io_error(
&server->io));
rc = -1;
break;
} else {
/* If timeout try read again */
continue;
}
}

Expand Down Expand Up @@ -342,6 +347,23 @@ void od_rules_group_checker_run(void *arg)

od_router_close(router, group_checker_client);

if (rc == NOT_OK_RESPONSE) {
od_debug(&instance->logger, "group_checker",
group_checker_client, server,
"group check failed");

od_list_t *it, *n;
od_list_foreach_safe(&members, it, n)
{
member = od_container_of(
it, od_group_member_name_item_t,
link);
if (member)
free(member);
}
break;
}

bool have_default = false;
od_list_t *i;
int count_group_users = 0;
Expand Down

0 comments on commit 802396d

Please sign in to comment.