Skip to content

Commit 97889d8

Browse files
committed
BUGFIX:
- Sneaker: created empty sneaker.json if server was still unregistered - Logfiles were not written anymore after an DCS dump.
1 parent 4e850ca commit 97889d8

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

core/data/impl/nodeimpl.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from packaging.version import parse
3030
from pathlib import Path
3131
from psycopg import sql
32-
from psycopg.errors import UndefinedTable, InFailedSqlTransaction, ConnectionTimeout
32+
from psycopg.errors import UndefinedTable, InFailedSqlTransaction, ConnectionTimeout, UniqueViolation
3333
from psycopg.types.json import Json
3434
from psycopg_pool import ConnectionPool, AsyncConnectionPool
3535
from typing import Optional, Union, Awaitable, Callable, Any, cast
@@ -350,8 +350,12 @@ async def init_instances(self):
350350
""", (self.name,))
351351
# initialize the nodes
352352
for _name, _element in self.locals.pop('instances', {}).items():
353-
instance = DataObjectFactory().new(InstanceImpl, node=self, name=_name, locals=_element)
354-
self.instances.append(instance)
353+
try:
354+
instance = DataObjectFactory().new(InstanceImpl, node=self, name=_name, locals=_element)
355+
self.instances.append(instance)
356+
except UniqueViolation:
357+
self.log.error(f"Instance \"{_name}\" can't be added."
358+
f"There is an instance already with the same server name or bot port.")
355359

356360
async def update_db(self):
357361
# Initialize the cluster tables ...

core/utils/validators.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,11 @@ def file_exists(value, _, path):
104104
return True
105105

106106
def unique_port(value, _, path):
107-
if not isinstance(value, int) or value < 1024 or value > 65535:
107+
try:
108+
value = int(value)
109+
if value < 1024 or value > 65535:
110+
raise ValueError
111+
except ValueError:
108112
raise SchemaError(msg=f"{value} is not a valid port", path=path)
109113
node = path.split("/")[1]
110114
if node not in ports:

extensions/sneaker/extension.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def create_config(self):
7474
cfg['servers'] = [
7575
x for x in cfg['servers'] if x['name'] in [
7676
y.name for y in self.bus.servers.values()
77-
if y.status not in [Status.UNREGISTERED, Status.SHUTDOWN]
77+
if y.name == self.server.name or y.status not in [Status.UNREGISTERED, Status.SHUTDOWN]
7878
]
7979
]
8080
with open(filename, mode='w', encoding='utf-8') as file:

services/monitoring/service.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,16 @@ async def kill_hung_server(self, server: Server):
163163
try:
164164
filename = os.path.join(server.instance.home, 'Logs',
165165
f"{now.strftime('dcs-%Y%m%d-%H%M%S')}.dmp")
166+
167+
# Save all handlers before create_dump
168+
root = logging.getLogger()
169+
saved_handlers = root.handlers[:]
170+
166171
await asyncio.to_thread(create_dump, server.process.pid, filename,
167172
MINIDUMP_TYPE.MiniDumpNormal, True)
168173

169-
root = logging.getLogger()
170-
if root.handlers:
171-
root.removeHandler(root.handlers[0])
174+
# Restore the original loggers
175+
root.handlers = saved_handlers
172176
except OSError:
173177
self.log.debug("No minidump created due to an error (Linux?).")
174178
shutil.copy2(os.path.join(server.instance.home, 'Logs', 'dcs.log'),

0 commit comments

Comments
 (0)