History log of /haiku/src/tests/system/kernel/util/BOpenHashTableTest.cpp
Revision Date Author Comments
# 21127482 28-Jan-2020 Kyle Ambroff-Kao <kyle@ambroffkao.com>

tcp: Fix KDL when sockets are reused

This fixes a KDL that is triggered by the following scenario.

1. A socket is created, attempting to establish a session
between (loopback, ephemeral port) => (remote address, remote
port).
2. That socket ends up in the closed state because the remote is not
accepting connections.
3. The socket is re-used to connect to a different (remote address,
remote port).

The problem is that fConnectionHash is a BOpenHashTable<TCPEndpoint>,
and inserting endpoint multiple times can create a linked list
cycle (TCPEndpoint is an intrusive linked list node). That means that,
even though TCPEndpoint's destructor removes itself from
fConnectionHash, there will still be a pointer to it left behind,
which means that future accesses within that hash table bucket will
result in a segfault.

The added fConnectionHash.Remove(endpoint) here prevents the KDL, as
it ensures that socket reuse doesn't result in a cycle.

Fixes #13927, see that ticket for a detailed explanation of the
problem.

Also added some regression tests:
* Added SocketTests::ClientSocketReuseTest to PosixNetTest, which
reproduces this KDL.
* BOpenHashTable: Added tests to cover RemoveUnchecked and removal
of an object that isn't in the table.

Change-Id: If4bcc1e0d94350a5ad9ba8e7ae6f1b783b3f6d34
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2173
Reviewed-by: Stephan Aßmus <superstippi@gmx.de>


# aa7ac127 26-Jan-2020 Kyle Ambroff-Kao <kyle@ambroffkao.com>

tests/kernel: Add tests for BOpenHashTable

Linking libkernelutilstest.so with libbe to for use of BObjectList in
the tests.

Change-Id: I1abb991e240dd522821a71ef54d22a1ca7957283
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2165
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>