Skip to content

Commit fdfe6e4

Browse files
authored
Check for already running status code when launching core agent. (#786)
1 parent ebc5afb commit fdfe6e4

File tree

2 files changed

+6
-20
lines changed

2 files changed

+6
-20
lines changed

src/scout_apm/core/agent/manager.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import json
66
import logging
77
import os
8-
import signal
98
import subprocess
109
import tarfile
1110
import time
@@ -17,6 +16,8 @@
1716

1817
logger = logging.getLogger(__name__)
1918

19+
CA_ALREADY_RUNNING_EXIT_CODE = 3
20+
2021

2122
class CoreAgentManager(object):
2223
def __init__(self):
@@ -73,8 +74,10 @@ def run(self):
7374
stdout=devnull,
7475
)
7576
except subprocess.CalledProcessError as err:
76-
if err.returncode in [signal.SIGTERM, signal.SIGQUIT]:
77-
logger.debug("Core agent returned signal: {}".format(err.returncode))
77+
if err.returncode == CA_ALREADY_RUNNING_EXIT_CODE:
78+
# Other processes may have already started the core agent.
79+
logger.debug("Core agent already running.")
80+
return True
7881
else:
7982
logger.exception("CalledProcessError running Core Agent")
8083
return False

tests/integration/core/agent/test_manager.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -127,23 +127,6 @@ def test_launch_error(caplog, core_agent_manager):
127127
assert caplog.records[0].exc_info[1] is exception
128128

129129

130-
@pytest.mark.parametrize(["signal_code"], [[signal.SIGQUIT], [signal.SIGTERM]])
131-
def test_launch_expected_signal_error(signal_code, caplog, core_agent_manager):
132-
caplog.set_level(logging.ERROR)
133-
exception = subprocess.CalledProcessError(signal_code, "err")
134-
with mock.patch.object(
135-
manager.CoreAgentManager,
136-
"agent_binary",
137-
side_effect=exception,
138-
):
139-
result = core_agent_manager.launch()
140-
141-
assert not result
142-
assert not core_agent_is_running()
143-
# Caplog doesn't contain debug messages
144-
assert caplog.record_tuples == []
145-
146-
147130
def test_launch_unexpected_signal_error(caplog, core_agent_manager):
148131
caplog.set_level(logging.ERROR)
149132
exception = subprocess.CalledProcessError(signal.SIGINT, "err")

0 commit comments

Comments
 (0)