Skip to content

Commit ec56592

Browse files
author
David Erb
committed
disconnect database if activate_coro fails
1 parent e76a4e8 commit ec56592

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/dls_servbase_lib/datafaces/aiohttp.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def __init__(self, specification=None):
4545
# ----------------------------------------------------------------------------------------
4646
def callsign(self):
4747
""""""
48-
return "%s %s" % ("Dataface.Aiohttp", BaseAiohttp.callsign(self))
48+
return "%s %s" % ("Servbase.Dataface", BaseAiohttp.callsign(self))
4949

5050
# ----------------------------------------------------------------------------------------
5151
def activate_process(self):
@@ -68,7 +68,7 @@ def activate_thread(self, loop):
6868
"""
6969

7070
try:
71-
threading.current_thread().name = "dls_servbase_dataface"
71+
threading.current_thread().name = "servbase_dataface"
7272

7373
self.activate_thread_base(loop)
7474

@@ -99,7 +99,16 @@ async def activate_coro(self):
9999
await self.activate_coro_base(route_tuples)
100100

101101
except Exception:
102-
raise RuntimeError(f"unable to start {callsign(self)} server coro")
102+
# We managed to get a dataface alive?
103+
if self.__actual_dls_servbase_dataface is not None:
104+
# Need to disconnect it so outer asyncio loop will quit.
105+
logger.debug(
106+
f"[THRDIEP] {callsign(self)} disconnecting after failure to activate coro"
107+
)
108+
109+
await self.__actual_dls_servbase_dataface.disconnect()
110+
111+
raise RuntimeError(f"{callsign(self)} was unable to activate_coro")
103112

104113
# ----------------------------------------------------------------------------------------
105114
async def direct_shutdown(self):

src/dls_servbase_lib/datafaces/normsql.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ async def start(self):
3434
# ----------------------------------------------------------------------------------------
3535
async def disconnect(self):
3636
if self.__database is not None:
37+
logger.debug(
38+
"[THRDIEP] disconnecting from actual servbase dataface normsql implementation"
39+
)
3740
await self.__database.disconnect()
3841
self.__database = None
3942

0 commit comments

Comments
 (0)