beyond-all-reason / beyond-all-reason/RecoilEngine

Engine crashing due to unsafe lua socket api

Open
#1,786 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
679
Forks
290
Avg merge
3d 2h
Merged PRs (30d)
40

Description

**note:**read [comment below](https://github.com/beyond-all-reason/RecoilEngine/issues/1786#issuecomment-2505082209) for actual description of the issue.

### Description

This problem might be linux only, not sure.

When running chobby directly (as documented [here](https://github.com/beyond-all-reason/Beyond-All-Reason/wiki/Testing-New-Engine-Releases-in-BAR#using-a-local-version-directly)) with the engine instead of through launcher it will quickly corrupt and crash. It seems to start ok, but after starting skirmish it will corrupt and die in less than a minute.

Also if I try to go back to lobby lots of images seem to be missing at the point of the corruption.

**update**: This is caused by resource exhaustion due to not properly closing luasockets in chobby. See https://github.com/beyond-all-reason/BYAR-Chobby/pull/827

### More information

I have tried this with many different engine versions, as far as the fork from [#1774](https://github.com/beyond-all-reason/spring/pull/1774), also master, with and without my personal branches.

All the tests I did are from running spring directly from host os (as opposed to running through flatpak), so this could be also because of custom build instead of something to do with chobby, still I think I have pinpointed the problem to specific module in chobby.

Corruption starts to manifest as errors with images, sounds or fonts (maybe vfs access related no idea).

Not totally sure what's going on, but seems to be related to repeated calling `client = socket.tcp()`. I'm still debugging this to get a more final assesment and have no idea how that could be causing the problem tbh.

The problem definitely comes from [api_spring_launcher.lua](https://github.com/beyond-all-reason/BYAR-Chobby/blob/master/libs/spring-launcher/luaui/widgets/api_spring_launcher.lua). Commenting all SocketConnect calls seems to make the issue go away.

This is something that can be worked around in chobby so the engine doesn't crash, but posting here so it can be properly investigated since it could be affecting other situations.

### Error logs

This error usually crashes the game although I think it doesn't always show:

```
(no errors before this line)
[t=00:01:13.081375][f=0000315] Fatal: [ExitSpringProcess] errorMsg="vector::_M_default_append" msgCaption="Spring: caught std::logic_error" mainThread=1
[t=00:01:13.081504][f=0000315] Error: [Watchdog::ClearTimer(id)] Invalid thread 4 (_threadId=(nil))
```

When commenting SocketConnect from api_spring_launcher only in Update, it seems to take a few seconds more to crash, and also show some symptoms before the crash:

```
[t=00:00:31.103424][f=0000031] Loaded atmosphere CEGs config for map: Quicksilver Remake 1.24
[t=00:00:33.103939][f=0000091] [Sound] Error: [LoadWAV(sounds/atmos/windy1.wav)] invalid header
[t=00:00:33.103954][f=0000091] [Sound] Warning: [LoadSoundBuffer] failed to load file "sounds/atmos/windy1.wav"
[t=00:00:33.436761][f=0000100] [Sound] Error: [LoadWAV(sounds/buildings/arm-bld-metal.wav)] invalid header
[t=00:00:33.436780][f=0000100] [Sound] Warning: [LoadSoundBuffer] failed to load file "sounds/buildings/arm-bld-metal.wav"
[t=00:00:33.436813][f=0000100] [Sound] Error: [LoadWAV(sounds/buildings/arm-bld-mex.wav)] invalid header
[t=00:00:33.436829][f=0000100] [Sound] Warning: [LoadSoundBuffer] failed to load file "sounds/buildings/arm-bld-mex.wav"
[t=00:00:33.454693][f=0000101] Warning: Couldn't find texture "LuaUI/Images/commandsfx/line.dds"!
[t=00:00:33.536974][f=0000104] [Sound] Error: [LoadWAV(sounds/atmos/beach4.wav)] invalid header
[t=00:00:33.536988][f=0000104] [Sound] Warning: [LoadSoundBuffer] failed to load file "sounds/atmos/beach4.wav"
[t=00:00:35.636978][f=0000167] [Sound] Error: [LoadWAV(sounds/atmos/beach5.wav)] invalid header
[t=00:00:35.637006][f=0000167] [Sound] Warning: [LoadSoundBuffer] failed to load file "sounds/atmos/beach5.wav"
[t=00:00:35.903652][f=0000175] [Sound] Error: [LoadWAV(sounds/atmos/windy4.wav)] invalid header
[t=00:00:35.903666][f=0000175] [Sound] Warning: [LoadSoundBuffer] failed to load file "sounds/atmos/windy4.wav"
[t=00:00:36.570943][f=0000195] [WatchDog::DeregisterThread] deregistering controls for thread [main]
[t=00:00:43.443528][f=0000195] Fatal: [ExitSpringProcess] errorMsg="vector::_M_default_append" msgCaption="Spring: caught std::logic_error" mainThread=1
[t=00:00:43.443674][f=0000195] Error: [Watchdog::ClearTimer(id)] Invalid thread 4 (_threadId=(nil))
```

Contributor guide

Open the contributing guide

Research direction

Start with BYAR-Chobby's libs/spring-launcher/luaui/widgets/api_spring_launcher.lua, especially SocketConnect and the repeated socket.tcp() calls. Read the linked BYAR-Chobby pull request #827 and compare its resource-exhaustion diagnosis with the engine crash logs. Done means launching chobby directly, starting a skirmish, and returning to the lobby without corruption or a crash.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, lua
Domain
backend, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.