fix potential race in socket closure
This commit is contained in:
@@ -335,7 +335,7 @@ asio::awaitable<WebSocketMessage> HTTPClient::recv_websocket_message(size_t max_
|
|||||||
} else if (opcode == 0x08) {
|
} else if (opcode == 0x08) {
|
||||||
// Close message
|
// Close message
|
||||||
co_await this->send_websocket_message(msg.data, msg.opcode);
|
co_await this->send_websocket_message(msg.data, msg.opcode);
|
||||||
this->r.get_socket().close();
|
this->r.close();
|
||||||
|
|
||||||
} else if (opcode == 0x09) {
|
} else if (opcode == 0x09) {
|
||||||
// Ping message
|
// Ping message
|
||||||
@@ -343,7 +343,7 @@ asio::awaitable<WebSocketMessage> HTTPClient::recv_websocket_message(size_t max_
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Unknown control message type
|
// Unknown control message type
|
||||||
this->r.get_socket().close();
|
this->r.close();
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -351,7 +351,7 @@ asio::awaitable<WebSocketMessage> HTTPClient::recv_websocket_message(size_t max_
|
|||||||
// If there's an existing fragment, the current message's opcode should be
|
// If there's an existing fragment, the current message's opcode should be
|
||||||
// zero; if there's no pending message, it must not be zero
|
// zero; if there's no pending message, it must not be zero
|
||||||
if (prev_msg_present == (opcode != 0)) {
|
if (prev_msg_present == (opcode != 0)) {
|
||||||
this->r.get_socket().close();
|
this->r.close();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-1
@@ -189,8 +189,14 @@ public:
|
|||||||
return this->sock;
|
return this->sock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool is_open() const {
|
||||||
|
return this->sock.is_open();
|
||||||
|
}
|
||||||
|
|
||||||
inline void close() {
|
inline void close() {
|
||||||
this->sock.close();
|
if (this->sock.is_open()) {
|
||||||
|
this->sock.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
+3
-1
@@ -118,7 +118,9 @@ vector<shared_ptr<Client>> GameServer::get_clients_by_identifier(const string& i
|
|||||||
shared_ptr<Client> GameServer::create_client(shared_ptr<GameServerSocket> listen_sock, asio::ip::tcp::socket&& client_sock) {
|
shared_ptr<Client> GameServer::create_client(shared_ptr<GameServerSocket> listen_sock, asio::ip::tcp::socket&& client_sock) {
|
||||||
uint32_t addr = ipv4_addr_for_asio_addr(client_sock.remote_endpoint().address());
|
uint32_t addr = ipv4_addr_for_asio_addr(client_sock.remote_endpoint().address());
|
||||||
if (this->state->banned_ipv4_ranges->check(addr)) {
|
if (this->state->banned_ipv4_ranges->check(addr)) {
|
||||||
client_sock.close();
|
if (client_sock.is_open()) {
|
||||||
|
client_sock.close();
|
||||||
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -154,7 +154,9 @@ void IPSSClient::reschedule_idle_timeout() {
|
|||||||
this->idle_timeout_timer.async_wait([this, sim](std::error_code ec) {
|
this->idle_timeout_timer.async_wait([this, sim](std::error_code ec) {
|
||||||
if (!ec) {
|
if (!ec) {
|
||||||
sim->log.info_f("Idle timeout expired on N-{:X}", this->network_id);
|
sim->log.info_f("Idle timeout expired on N-{:X}", this->network_id);
|
||||||
this->sock.close();
|
if (this->sock.is_open()) {
|
||||||
|
this->sock.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -1233,11 +1235,9 @@ asio::awaitable<void> IPStackSimulator::on_client_tcp_frame(shared_ptr<IPSSClien
|
|||||||
|
|
||||||
// Send the new data to the server
|
// Send the new data to the server
|
||||||
if (!conn->server_channel) {
|
if (!conn->server_channel) {
|
||||||
this->log.warning_f("Client sent data on TCP connection {}, but server channel is missing",
|
this->log.warning_f("Client sent data on TCP connection {}, but server channel is missing", conn_str);
|
||||||
conn_str);
|
|
||||||
} else if (!conn->server_channel->connected()) {
|
} else if (!conn->server_channel->connected()) {
|
||||||
this->log.warning_f("Client sent data on TCP connection {}, but server channel is disconnected",
|
this->log.warning_f("Client sent data on TCP connection {}, but server channel is disconnected", conn_str);
|
||||||
conn_str);
|
|
||||||
} else {
|
} else {
|
||||||
conn->server_channel->add_inbound_data(payload, payload_size);
|
conn->server_channel->add_inbound_data(payload, payload_size);
|
||||||
}
|
}
|
||||||
@@ -1425,7 +1425,9 @@ std::shared_ptr<IPSSClient> IPStackSimulator::create_client(
|
|||||||
std::shared_ptr<IPSSSocket> listen_sock, asio::ip::tcp::socket&& client_sock) {
|
std::shared_ptr<IPSSSocket> listen_sock, asio::ip::tcp::socket&& client_sock) {
|
||||||
uint32_t addr = ipv4_addr_for_asio_addr(client_sock.remote_endpoint().address());
|
uint32_t addr = ipv4_addr_for_asio_addr(client_sock.remote_endpoint().address());
|
||||||
if (this->state->banned_ipv4_ranges->check(addr)) {
|
if (this->state->banned_ipv4_ranges->check(addr)) {
|
||||||
client_sock.close();
|
if (client_sock.is_open()) {
|
||||||
|
client_sock.close();
|
||||||
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user