Skip to content

Commit

Permalink
fix(server): Fix infinite loop when the discovery server cannot be re…
Browse files Browse the repository at this point in the history
…ached
  • Loading branch information
jpfr committed Nov 14, 2023
1 parent 9073ee2 commit 8147cbd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/server/ua_discovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,12 @@ discoveryClientStateCallback(UA_Client *client,

/* Connection fully closed */
if(channelState == UA_SECURECHANNELSTATE_CLOSED) {
if(ar->shutdown)
if(!ar->connectSuccess || ar->shutdown) {
asyncRegisterRequest_clearAsync(ar); /* Clean up */
else
} else {
ar->connectSuccess = false;
__UA_Client_connect(client, true); /* Reconnect */
}
}
return;
}
Expand All @@ -363,6 +365,9 @@ discoveryClientStateCallback(UA_Client *client,
if(channelState != UA_SECURECHANNELSTATE_OPEN)
return;

/* We have at least succeeded to connect */
ar->connectSuccess = true;

/* Is this the encrypted SecureChannel already? (We might have to wait for
* the second connection after the FindServers handshake */
UA_MessageSecurityMode msm = UA_MESSAGESECURITYMODE_INVALID;
Expand Down Expand Up @@ -499,6 +504,7 @@ UA_Server_register(UA_Server *server, UA_ClientConfig *cc, UA_Boolean unregister

/* Connect asynchronously. The register service is called once the
* connection is open. */
ar->connectSuccess = false;
return __UA_Client_connect(ar->client, true);
}

Expand Down
1 change: 1 addition & 0 deletions src/server/ua_discovery.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ typedef struct {

UA_Boolean register2;
UA_Boolean shutdown;
UA_Boolean connectSuccess;
} asyncRegisterRequest;
#define UA_MAXREGISTERREQUESTS 4

Expand Down

0 comments on commit 8147cbd

Please sign in to comment.