Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid machinarium call with router lock #606

Merged
merged 3 commits into from
Apr 10, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions sources/router.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,20 @@ od_router_status_t od_router_route(od_router_t *router, od_client_t *client)
kiwi_be_startup_t *startup = &client->startup;
od_instance_t *instance = router->global->instance;

struct sockaddr_storage sa;
int salen;
struct sockaddr *saddr;
int rc;
salen = sizeof(sa);
saddr = (struct sockaddr *)&sa;
if (client->type == OD_POOL_CLIENT_EXTERNAL)
{
rc = machine_getpeername(client->io.io, saddr, &salen);
if (rc == -1) {
return OD_ROUTER_ERROR;
}
}

/* match route */
assert(startup->database.value_len);
assert(startup->user.value_len);
Expand All @@ -354,10 +368,6 @@ od_router_status_t od_router_route(od_router_t *router, od_client_t *client)
od_rule_t *rule =
NULL; // initialize rule for (line 365) and flag '-Wmaybe-uninitialized'

struct sockaddr_storage sa;
int salen;
struct sockaddr *saddr;
int rc;
int sequential = instance->config.sequential_routing;
switch (client->type) {
case OD_POOL_CLIENT_INTERNAL:
Expand All @@ -366,13 +376,6 @@ od_router_status_t od_router_route(od_router_t *router, od_client_t *client)
sequential);
break;
case OD_POOL_CLIENT_EXTERNAL:
salen = sizeof(sa);
saddr = (struct sockaddr *)&sa;
rc = machine_getpeername(client->io.io, saddr, &salen);
if (rc == -1) {
od_router_unlock(router);
return OD_ROUTER_ERROR;
}
rule = od_rules_forward(&router->rules, startup->database.value,
startup->user.value, &sa, 0,
sequential);
Expand Down
Loading