Skip to content

Commit a890264

Browse files
committed
fix(debugger): improve termination handling
fixes: [BUG] OSError: [Errno 22] Invalid argument and No incoming connection from debugger client #389
1 parent 5f1f5c3 commit a890264

File tree

6 files changed

+41
-14
lines changed

6 files changed

+41
-14
lines changed

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,11 +1768,13 @@
17681768
"string"
17691769
],
17701770
"enum": [
1771+
"none",
17711772
"default",
17721773
"test",
17731774
"test-profile"
17741775
],
17751776
"markdownEnumDescriptions": [
1777+
"No purpose defined.",
17761778
"Configuration is uses as default for all other configurations.",
17771779
"Default configuration for running or debugging tests.",
17781780
"Defines a test profile that you can select in the test explorer or via the play button during a test. This configuration is used instead of the configuration with the purpose `test`."
@@ -1781,11 +1783,13 @@
17811783
"description": "Defines what purpose this configuration has.",
17821784
"items": {
17831785
"enum": [
1786+
"none",
17841787
"default",
17851788
"test",
17861789
"test-profile"
17871790
],
17881791
"markdownEnumDescriptions": [
1792+
"No purpose defined.",
17891793
"Configuration is uses as default for all other configurations.",
17901794
"Default configuration for running or debugging tests.",
17911795
"Defines a test profile that you can select in the test explorer or via the play button during a test. This configuration is used instead of the configuration with the purpose `test`."

packages/debugger/src/robotcode/debugger/dap_types.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,26 @@ class TerminateResponse(Response):
622622
pass
623623

624624

625+
class RestartArguments(Model):
626+
arguments: Union[LaunchRequestArguments | AttachRequestArguments]
627+
628+
629+
@dataclass
630+
class _RestartRequest:
631+
arguments: Optional[RestartArguments] = None
632+
633+
634+
@dataclass
635+
class RestartRequest(Request, _RestartRequest):
636+
arguments: Optional[RestartArguments] = None
637+
command: str = "restart"
638+
639+
640+
@dataclass
641+
class RestartResponse(Response):
642+
pass
643+
644+
625645
@dataclass
626646
class StackFrameFormat(Model):
627647
parameters: Optional[bool] = None

packages/debugger/src/robotcode/debugger/debugger.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,10 @@ def check_thread_id(self, thread_id: int) -> None:
449449
if not self.main_thread_is_alive and thread_id != self.main_thread_id:
450450
raise InvalidThreadIdError(thread_id, self.main_thread_id)
451451

452+
def continue_all_if_paused(self) -> None:
453+
if self.state == State.Paused:
454+
self.continue_all()
455+
452456
def continue_all(self) -> None:
453457
if self.main_thread_is_alive:
454458
self.continue_thread(self.main_thread_id)

packages/debugger/src/robotcode/debugger/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,12 +260,12 @@ def run_debugger(
260260
)
261261
)
262262

263-
server.protocol.exit(exit_code)
264263
except CancelledError:
265264
pass
266265
finally:
267266
if server.protocol.connected:
268267
server.protocol.terminate()
268+
server.protocol.exit(exit_code)
269269

270270
if not server.protocol.wait_for_disconnected():
271271
app.verbose("Timeout to get disconnected from client")

packages/debugger/src/robotcode/debugger/server.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,19 +189,21 @@ def terminate(self) -> None:
189189
async def _terminate(
190190
self,
191191
arguments: Optional[TerminateArguments] = None,
192+
restart: Optional[bool] = None,
192193
*args: Any,
193194
**kwargs: Any,
194195
) -> None:
195-
if not self._sigint_signaled:
196+
Debugger.instance().terminate()
197+
198+
if not restart and not self._sigint_signaled:
196199
self._logger.info("Send SIGINT to process")
197200
signal.raise_signal(signal.SIGINT)
198201
self._sigint_signaled = True
199-
# Debugger.instance().continue_all()
202+
203+
Debugger.instance().continue_all_if_paused()
200204
else:
201205
await self.send_event_async(Event("terminateRequested"))
202206

203-
Debugger.instance().terminate()
204-
205207
self._logger.info("Send SIGTERM to process")
206208
signal.raise_signal(signal.SIGTERM)
207209

tests/robotcode/language_server/robotframework/parts/data/.vscode/launch.json

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,18 @@
3838
"presentation": {
3939
"hidden": true
4040
},
41-
},
42-
{
43-
"name": "RobotCode: Default",
44-
"type": "robotcode",
45-
"request": "launch",
46-
"purpose": "test",
47-
"presentation": {
48-
"hidden": true
49-
},
5041
// "robotCodeArgs": [
5142
// "-v",
5243
// "--log",
5344
// "--log-level=TRACE",
5445
// "--log-calls"
5546
// ],
47+
// "launcherExtraArgs": [
48+
// "-v",
49+
// "--log",
50+
// "--log-level=TRACE",
51+
// "--log-calls"
52+
// ],
5653
"profiles": [
5754
"ci*",
5855
"firefox",

0 commit comments

Comments
 (0)