mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-03 23:25:20 +00:00
Kernel: Migrate TCP socket tables locking to ProtectedValue
Note: TCPSocket::create_client() has a dubious locking process where the sockets by tuple table is first shared lock to check if the socket exists and bail out if it does, then unlocks, then exclusively locks to add the tuple. There could be a race condition where two client creation requests for the same tuple happen at the same time and both cleared the shared lock check. When in doubt, lock exclusively the whole time.
This commit is contained in:
committed by
Andreas Kling
parent
583abc27d8
commit
9216c72bfe
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <Kernel/Debug.h>
|
||||
#include <Kernel/Locking/Mutex.h>
|
||||
#include <Kernel/Locking/ProtectedValue.h>
|
||||
#include <Kernel/Net/ARP.h>
|
||||
#include <Kernel/Net/EtherType.h>
|
||||
#include <Kernel/Net/EthernetFrameHeader.h>
|
||||
@@ -639,11 +640,9 @@ void retransmit_tcp_packets()
|
||||
// We must keep the sockets alive until after we've unlocked the hash table
|
||||
// in case retransmit_packets() realizes that it wants to close the socket.
|
||||
NonnullRefPtrVector<TCPSocket, 16> sockets;
|
||||
{
|
||||
MutexLocker locker(TCPSocket::sockets_for_retransmit().lock(), LockMode::Shared);
|
||||
for (auto& socket : TCPSocket::sockets_for_retransmit().resource())
|
||||
sockets.append(*socket);
|
||||
}
|
||||
TCPSocket::sockets_for_retransmit().for_each_shared([&](const auto& socket) {
|
||||
sockets.append(*socket);
|
||||
});
|
||||
|
||||
for (auto& socket : sockets) {
|
||||
MutexLocker socket_locker(socket.lock());
|
||||
|
||||
Reference in New Issue
Block a user