Browse Source

Merge pull request #107643 from stuartcarnie/remote_debug_fix

Core: Fix data race in remote debugger; handle errors
Thaddeus Crews 2 months ago
parent
commit
3d94ba0f84
1 changed files with 12 additions and 7 deletions
  1. 12 7
      core/debugger/remote_debugger_peer.cpp

+ 12 - 7
core/debugger/remote_debugger_peer.cpp

@@ -44,8 +44,10 @@ bool RemoteDebuggerPeerTCP::has_message() {
 
 
 Array RemoteDebuggerPeerTCP::get_message() {
 Array RemoteDebuggerPeerTCP::get_message() {
 	MutexLock lock(mutex);
 	MutexLock lock(mutex);
-	ERR_FAIL_COND_V(!has_message(), Array());
-	Array out = in_queue.front()->get();
+	List<Array>::Element *E = in_queue.front();
+	ERR_FAIL_NULL_V_MSG(E, Array(), "No remote debugger messages in queue.");
+
+	Array out = E->get();
 	in_queue.pop_front();
 	in_queue.pop_front();
 	return out;
 	return out;
 }
 }
@@ -96,11 +98,13 @@ void RemoteDebuggerPeerTCP::_write_out() {
 	while (tcp_client->get_status() == StreamPeerTCP::STATUS_CONNECTED && tcp_client->wait(NetSocket::POLL_TYPE_OUT) == OK) {
 	while (tcp_client->get_status() == StreamPeerTCP::STATUS_CONNECTED && tcp_client->wait(NetSocket::POLL_TYPE_OUT) == OK) {
 		uint8_t *buf = out_buf.ptrw();
 		uint8_t *buf = out_buf.ptrw();
 		if (out_left <= 0) {
 		if (out_left <= 0) {
-			if (out_queue.is_empty()) {
-				break; // Nothing left to send
-			}
 			mutex.lock();
 			mutex.lock();
-			Variant var = out_queue.front()->get();
+			List<Array>::Element *E = out_queue.front();
+			if (!E) {
+				mutex.unlock();
+				break;
+			}
+			Variant var = E->get();
 			out_queue.pop_front();
 			out_queue.pop_front();
 			mutex.unlock();
 			mutex.unlock();
 			int size = 0;
 			int size = 0;
@@ -163,7 +167,8 @@ Error RemoteDebuggerPeerTCP::connect_to_host(const String &p_host, uint16_t p_po
 	const int tries = 6;
 	const int tries = 6;
 	const int waits[tries] = { 1, 10, 100, 1000, 1000, 1000 };
 	const int waits[tries] = { 1, 10, 100, 1000, 1000, 1000 };
 
 
-	tcp_client->connect_to_host(ip, port);
+	Error err = tcp_client->connect_to_host(ip, port);
+	ERR_FAIL_COND_V_MSG(err != OK, err, vformat("Remote Debugger: Unable to connect to host '%s:%d'.", p_host, port));
 
 
 	for (int i = 0; i < tries; i++) {
 	for (int i = 0; i < tries; i++) {
 		tcp_client->poll();
 		tcp_client->poll();