Skip to content

Commit f379544

Browse files
committed
fix(sim): tolerate webots-controller SIGSEGV on TCP disconnect
webots-controller crashes with SIGSEGV (exit 139) in libController.so when the remote Webots host closes the TCP connection. Replace the raw shell action with a subprocess wrapper that treats exit code 139 as success, since the DCS process itself exits cleanly at that point. Also replace `return status` with `exit(status)` in main() to bypass C++ static destructor teardown: ~webots::Robot() calls wb_robot_cleanup() and ~MqttClient() calls mosquitto_loop_stop(), both of which crash or block when the Webots connection is already gone.
1 parent 4e43b18 commit f379544

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

lib/MainNative/src/main.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,12 @@ extern int main(int argc, char** argv)
291291
}
292292
}
293293

294-
return status;
294+
/* Use exit() instead of return to skip C++ static destructor teardown.
295+
* ~webots::Robot() calls wb_robot_cleanup() and ~MqttClient() calls
296+
* mosquitto_loop_stop(), both of which crash or block when Webots has
297+
* already closed the connection.
298+
*/
299+
exit(status);
295300
}
296301

297302
/******************************************************************************

scripts/webots_launcher.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
print(f"OS type {OS_PLATFORM_TYPE} not supported.")
8686
sys.exit(1)
8787

88-
WEBOTS_LAUNCHER_ACTION = WEBOTS_CONTROLLER + ' '\
88+
WEBOTS_LAUNCHER_CMD = WEBOTS_CONTROLLER + ' '\
8989
+ WEBOTS_CONTROLLER_OPTIONS + ' ' \
9090
+ PROGRAM_PATH + PROGRAM_NAME + ' ' \
9191
+ PROGRAM_OPTIONS
@@ -147,6 +147,21 @@ def check_webots_ready(source, target, env): # pylint: disable=unused-argument
147147
_abort_missing_slot(protocol, ip, robot_name)
148148

149149

150+
def launch_webots_controller(source, target, env): # pylint: disable=unused-argument
151+
"""Run webots-controller, tolerating SIGSEGV (exit 139) on TCP disconnect.
152+
153+
webots-controller segfaults in libController.so when the remote Webots host
154+
closes the TCP connection. The DCS process itself exits cleanly; the crash
155+
is inside the launcher binary and is harmless.
156+
"""
157+
import subprocess
158+
cmd = env.subst(WEBOTS_LAUNCHER_CMD)
159+
print(cmd)
160+
result = subprocess.run(cmd, shell=True)
161+
if result.returncode not in (0, -11, 139): # 139 = 128 + SIGSEGV(11)
162+
env.Exit(result.returncode)
163+
164+
150165
################################################################################
151166
# Main
152167
################################################################################
@@ -157,7 +172,7 @@ def check_webots_ready(source, target, env): # pylint: disable=unused-argument
157172
dependencies=PROGRAM_PATH + PROGRAM_NAME,
158173
actions=[
159174
check_webots_ready,
160-
WEBOTS_LAUNCHER_ACTION
175+
launch_webots_controller,
161176
],
162177
title="Launch",
163178
description="Launch application with Webots launcher."

0 commit comments

Comments
 (0)