From 53ad3138fb39d412952339b923d42121b66825d5 Mon Sep 17 00:00:00 2001 From: "ChenYing Kuo (CY)" Date: Fri, 13 Sep 2024 20:56:58 +0800 Subject: [PATCH] Update the if-condition of return type to ensure it will fail if rest (#1416) server is not running successfully. Signed-off-by: ChenYing Kuo --- DEFAULT_CONFIG.json5 | 2 +- plugins/zenoh-plugin-rest/src/lib.rs | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/DEFAULT_CONFIG.json5 b/DEFAULT_CONFIG.json5 index e7672c6057..b318b5debd 100644 --- a/DEFAULT_CONFIG.json5 +++ b/DEFAULT_CONFIG.json5 @@ -505,7 +505,7 @@ // http_port: 8000, // /// The number of worker thread in TOKIO runtime (default: 2) // /// The configuration only takes effect if running as a dynamic plugin, which can not reuse the current runtime. - // work_thread_num: 0, + // work_thread_num: 2, // /// The number of blocking thread in TOKIO runtime (default: 50) // /// The configuration only takes effect if running as a dynamic plugin, which can not reuse the current runtime. // max_block_thread_num: 50, diff --git a/plugins/zenoh-plugin-rest/src/lib.rs b/plugins/zenoh-plugin-rest/src/lib.rs index 90dd6002df..ace93275a8 100644 --- a/plugins/zenoh-plugin-rest/src/lib.rs +++ b/plugins/zenoh-plugin-rest/src/lib.rs @@ -290,7 +290,9 @@ impl Plugin for RestPlugin { timeout(Duration::from_millis(1), TOKIO_RUNTIME.spawn(task)).await }); - if let Ok(Err(e)) = task { + // The spawn task (TOKIO_RUNTIME.spawn(task)) should not return immediately. The server should block inside. + // If it returns immediately (for example, address already in use), we can get the error inside Ok + if let Ok(Ok(Err(e))) = task { bail!("REST server failed within 1ms: {e}") } Ok(Box::new(RunningPlugin(conf)))