Skip to content

Commit 279de66

Browse files
rlubosfabiobaltieri
authored andcommitted
net: lwm2m: Stop the LwM2M engine in case of fatal network error
In case of fatal network error (i.e. when the LwM2M client runs out of retries), call lwm2m_engine_stop() to cleanup any allocated resources for the client. The engine is dead at that point anyway so the application needs to recover. If this isn't done, it is theoretically possible to restart the LwM2M client (with lwm2m_rd_client_start() which does not report an error in such case), which in turn could lead to resource leaks (like for example the observer list is reinitialized) if the application didn't call lwm2m_rd_client_stop() first. Calling lwm2m_engine_stop() ensures that all resources are freed even if the application doesn't call stop before restarting. Stopping the engine is also needed when the network error occurs when de-registering - in such case the engine goes straight into the IDLE state, where it's possible to restart the client and thus reinitialize the observer lists. Signed-off-by: Robert Lubos <[email protected]>
1 parent 5c1d4db commit 279de66

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

subsys/net/lib/lwm2m/lwm2m_rd_client.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ static void socket_fault_cb(int error)
391391
sm_handle_timeout_state(ENGINE_NETWORK_ERROR);
392392
} else if (client.engine_state != ENGINE_SUSPENDED &&
393393
!client.server_disabled) {
394+
lwm2m_engine_stop(client.ctx);
394395
sm_handle_timeout_state(ENGINE_IDLE);
395396
}
396397
}
@@ -1413,6 +1414,7 @@ static void sm_do_network_error(void)
14131414
stop_engine:
14141415

14151416
/* We are out of options, stop engine */
1417+
lwm2m_engine_stop(client.ctx);
14161418
if (client.ctx->event_cb) {
14171419
if (client.ctx->bootstrap_mode) {
14181420
client.ctx->event_cb(client.ctx,

0 commit comments

Comments
 (0)