Skip to content

Commit

Permalink
always send initial service event (#561)
Browse files Browse the repository at this point in the history
fix zitilib crash on service not found
  • Loading branch information
ekoby authored Oct 2, 2023
1 parent 104e635 commit 8063e46
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
1 change: 1 addition & 0 deletions inc_internal/zt_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ struct ziti_ctx {
uv_timeval64_t session_received_at;
ziti_identity_data *identity_data;

bool services_loaded;
// map<name,ziti_service>
model_map services;
// map<service_id,ziti_net_session>
Expand Down
16 changes: 9 additions & 7 deletions library/ziti.c
Original file line number Diff line number Diff line change
Expand Up @@ -787,16 +787,16 @@ static void set_service_flags(ziti_service *s) {

static void service_cb(ziti_service *s, const ziti_error *err, void *ctx) {
struct service_req_s *req = ctx;
int rc = err ? err->err : ZITI_OK;
int rc = ZITI_SERVICE_UNAVAILABLE;

if (s != NULL) {
set_service_flags(s);
ziti_service *old = model_map_set(&req->ztx->services, s->name, s);
free_ziti_service_ptr(old);
}
else {
if (rc == ZITI_NOT_FOUND) {
rc = ZITI_SERVICE_UNAVAILABLE;
rc = ZITI_OK;
} else {
if (err) {
rc = err->err;
}
}

Expand Down Expand Up @@ -1188,9 +1188,11 @@ static void update_services(ziti_service_array services, const ziti_error *error
model_map_set(&ztx->services, s->name, s);
}

if (addIdx > 0 || remIdx > 0 || chIdx > 0) {
ZTX_LOG(DEBUG, "sending service event %zd added, %zd removed, %zd changed", addIdx, remIdx, chIdx);
if (!ztx->services_loaded || (addIdx + remIdx + chIdx) > 0) {
ZTX_LOG(DEBUG, "sending service event initial[%s] %zd added, %zd removed, %zd changed",
ztx->services_loaded ? "false" : "true", addIdx, remIdx, chIdx);
ziti_send_event(ztx, &ev);
ztx->services_loaded = true;
} else {
ZTX_LOG(VERBOSE, "no services added, changed, or removed");
}
Expand Down
4 changes: 2 additions & 2 deletions programs/sample-bridge/ziti-fd-client.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022. NetFoundry Inc.
// Copyright (c) 2022-2023. NetFoundry Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -62,7 +62,7 @@ int main(int argc, char *argv[]) {
long rc = service ? Ziti_connect(socket, ztx, service, "ziggy") : Ziti_connect_addr(socket, hostname, port);

if (rc != 0) {
fprintf(stderr, "failed to connect: %ld(%s)\n", rc, ziti_errorstr(rc));
fprintf(stderr, "failed to connect: %ld(%s)\n", rc, ziti_errorstr(Ziti_last_error()));
goto DONE;
}

Expand Down

0 comments on commit 8063e46

Please sign in to comment.