Skip to content

[BUG] Server crashes when connection is not closed properly #483

@Neptnium

Description

@Neptnium

Fill out general information
OS (windows, linux, ...): debian12
BeamMP-Server Version: v3.9.2

Describe the bug
When client crashes or ALT + F4, or any other case where the connection is not closed properly. The server might crash with a core dump.

To Reproduce
Steps to reproduce the behavior:

  1. Go on a server, and close the launcher !

Expected behavior
The server does not crahes (I guess 😆)

Logs
Sorry, there is nothing logged, just a SIGABRT.

Additional context
The server crashes with a SIGABRT caused by an uncaught boost::system::system_error exception escaping the thread's boundary, triggering std::terminate().

src/TNetwork.cpp:652:

void TNetwork::DisconnectClient(TClient &c, const std::string &R)
{
    if (c.IsDisconnected()) return;
    // THIS LINE THROWS when the socket is already closed:
    std::string ClientIP = c.GetTCPSock().remote_endpoint().address().to_string();
    mClientMapMutex.lock();
    if (mClientMap[ClientIP] > 0) {
        mClientMap[ClientIP]--;
    }
    if (mClientMap[ClientIP] == 0) {
        mClientMap.erase(ClientIP);
    }
    mClientMapMutex.unlock();
    c.Disconnect(R);
}

BUT, the fix is not as simple as a try / catch because of the mClientMap, my best bet would be to save the client's ip inside of TClient at all times. If you have any other idea, please tell me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions