Godot freezes even before running the function

Godot Version

v4.6.2.stable.official [71f334935]

Question

Hello!
I’m trying to make my little lan-only file transfer app in Godot,and I got an odd problem.Here’s the code first so i can explain properly.


func _try_sending(host_ip:String,host_port:int):
	var err = client_component._request_connection(host_ip,host_port)#just connects to the host
	if err == OK:
		stats.text = "Connecting..."

		await get_tree().create_timer(1).timeout
		
		stats.text = "Connected!"

		client_component._send_file("res://Test/test_files/large_sample.zip")
	else:
		stats.text = "Failed to connect!"

When the stats shows that it’s connecting, the game just crashes Godot! but it only happens when I send a file bigger then 1 MB.

Here’s the send file:

###=====================SEND===================###
func _send_file(path:String):
	var file_ = FileAccess.open(path,FileAccess.READ)
	var file_length : int = file_.get_length()
	

I have tried to open the file in a new project and it works as expected.
It just works smoothly with 500KB-ish files.
I’m using TCPStream to send the data, if it helps.

Little screenshot:


Normaly,after clicking send it almost immediately shows connected.
Thanks : )

Freezes or crashes? What does your TCP code look like? Keep in mind that basic TCP streams are blocking in Godot, sending or receiving files on the main thread will halt the entire game until the entire file is sent.

It freezes and then a few moments later it crashes.

func _send_file(path:String):
	var file_ = FileAccess.open(path,FileAccess.READ)
	var file_length : int = file_.get_length()

	var meta_data:Dictionary = {
		"Length":file_length,
		}
	
	if file_:
		#Send length
		socket.put_var(meta_data,true)
		#Send in chunks
		while file_.get_position() < file_length:
			#get a small portion of the file
			var send_chunk = file_.get_buffer(chunk_size)
			#Sends it
			socket.put_data(send_chunk)
		#Close the file after finishing : )
		file_.close()

I can confirm that the problem is not about networking at all.Because I found out that the _send_file was never running!

I’m doing both at the same time.Sending and receiving without two separate instances(because I’m lazy to send the project files to another device)

Hello!
Adding a little delay in the _send_file func fixed the issue.