@@ -37,7 +37,7 @@ namespace vix::websocket
3737 * @brief Runs a WebSocket server alongside an HTTP app, with shared lifecycle.
3838 *
3939 * Starts the WebSocket server immediately and coordinates shutdown with the attached HTTP
40- * application.
40+ * application. The supplied runtime executor is borrowed: this object never stops it.
4141 *
4242 * Important lifecycle rule:
4343 * - The HTTP shutdown callback only requests an asynchronous stop.
@@ -54,7 +54,7 @@ namespace vix::websocket
5454 *
5555 * @param app HTTP application instance.
5656 * @param ws WebSocket server instance.
57- * @param exec Shared runtime executor.
57+ * @param exec Borrowed shared runtime executor. Its caller retains lifecycle authority .
5858 */
5959 AttachedRuntime (
6060 vix::App &app,
@@ -150,8 +150,8 @@ namespace vix::websocket
150150 /* *
151151 * @brief Perform the final blocking shutdown exactly once.
152152 *
153- * Finalization order:
154- * 1. stop websocket blocking
153+ * Finalization stops the WebSocket server blocking. The supplied executor
154+ * is borrowed and remains under caller lifecycle control.
155155 */
156156 void finalize_shutdown () noexcept
157157 {
@@ -175,16 +175,6 @@ namespace vix::websocket
175175 {
176176 }
177177
178- try
179- {
180- if (exec_)
181- {
182- exec_->stop ();
183- }
184- }
185- catch (...)
186- {
187- }
188178 }
189179
190180 private:
@@ -213,7 +203,7 @@ namespace vix::websocket
213203 /* * @brief Attached WebSocket server. */
214204 vix::websocket::Server &ws_;
215205
216- /* * @brief Shared runtime executor. */
206+ /* * @brief Borrowed runtime executor retained for the attached server graph . */
217207 std::shared_ptr<vix::executor::RuntimeExecutor> exec_;
218208
219209 /* * @brief Shared shutdown state used by callbacks and finalization. */
@@ -253,7 +243,7 @@ namespace vix
253243 *
254244 * @param app HTTP application instance.
255245 * @param ws WebSocket server instance.
256- * @param exec Shared runtime executor.
246+ * @param exec Borrowed shared runtime executor. This function does not stop it .
257247 * @param cfg Core application configuration.
258248 */
259249 inline void run_http_and_ws (
@@ -306,7 +296,7 @@ namespace vix
306296 *
307297 * @param app HTTP application instance.
308298 * @param ws WebSocket server instance.
309- * @param exec Shared runtime executor.
299+ * @param exec Borrowed shared runtime executor. This function does not stop it .
310300 * @param port HTTP listening port.
311301 */
312302 inline void run_http_and_ws (
@@ -324,9 +314,10 @@ namespace vix
324314 /* *
325315 * @brief Build and serve a combined HTTP + WebSocket runtime from a config path.
326316 *
327- * Creates a shared runtime executor, constructs the HTTP app and WebSocket
328- * server, lets the caller configure routes and handlers, then runs both
329- * servers together.
317+ * Creates and owns a shared runtime executor, constructs the HTTP app and
318+ * WebSocket server, lets the caller configure routes and handlers, then runs
319+ * both servers together. The helper stops its executor when orchestration
320+ * completes or exits through its configuration/orchestration exception path.
330321 *
331322 * @tparam ConfigureFn Callable type.
332323 * @param configPath Path to the configuration file.
@@ -349,9 +340,18 @@ namespace vix
349340 vix::App app{exec};
350341 vix::websocket::Server ws{cfg, exec};
351342
352- fn (app, ws);
343+ try
344+ {
345+ fn (app, ws);
346+ run_http_and_ws (app, ws, exec, cfg);
347+ }
348+ catch (...)
349+ {
350+ exec->stop ();
351+ throw ;
352+ }
353353
354- run_http_and_ws (app, ws, exec, cfg );
354+ exec-> stop ( );
355355 }
356356
357357 /* *
0 commit comments