Skip to content

Commit 9a01f27

Browse files
committed
Debugger: Retry connection to host.
Connection to the server will fail immediately on non-Windows platforms. In these cases, the program will attempt to retry the connection on an interval up to a certain number of times before failing.
1 parent 2140ff7 commit 9a01f27

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

Assets/Scripts/Language/Debugger.gd

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ var ProcessID = 0
6868
# The frame data when the debugger breaks.
6969
var FrameData = {}
7070

71+
# The amount of times to retry the connection to the server. Non-Windows systems
72+
# does not have an initial connection delay and will error out immediately. We will
73+
# just retry up to a number of times before failing completely.
74+
var Retries = 0
75+
7176
func _ready() -> void:
7277
var _Error = Connection.connect("OnConnected", self, "OnClientConnected")
7378
_Error = Connection.connect("OnDisconnected", self, "OnClientDisconnected")
@@ -134,6 +139,7 @@ func Launch(Name := "") -> bool:
134139
Log.Clear()
135140
Log.Info("Launching debug session...")
136141

142+
Retries = 0
137143
if not Connection.Connect(PORT):
138144
return false
139145

@@ -209,7 +215,22 @@ func OnClientDisconnected() -> void:
209215

210216

211217
func OnClientConnectionError() -> void:
212-
emit_signal("OnStateChange", STATE.FAILED_TO_CONNECT)
218+
# Early failure may have occurred here. Attempt a retry. If max number is
219+
# reached, emit the signal.
220+
var Emit = false
221+
if Connection.IsConnecting() and Retries < 5:
222+
var Scene: SceneTree = Engine.get_main_loop()
223+
yield(Scene.create_timer(0.5), "timeout")
224+
225+
Retries += 1
226+
if not Connection.Connect(PORT):
227+
Emit = true
228+
else:
229+
Emit = true
230+
231+
if Emit:
232+
Log.Error("Failed to connect to remote debugging host.")
233+
emit_signal("OnStateChange", STATE.FAILED_TO_CONNECT)
213234

214235

215236
func OnServerDataReceived(Data: String) -> void:

Assets/Scripts/Language/DebuggerClient.gd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ func Disconnect() -> void:
6767

6868
func Update() -> void:
6969
if get_status() == STATUS_ERROR:
70-
Log.Error("Failed to connect to remote debugging host.")
7170
emit_signal("OnConnectionError")
7271
disconnect_from_host()
7372

@@ -84,3 +83,6 @@ func Update() -> void:
8483
State = STATE.DISCONNECTED
8584
emit_signal("OnDisconnected")
8685

86+
87+
func IsConnecting() -> bool:
88+
return State == STATE.CONNECTING

0 commit comments

Comments
 (0)