Skip to content

Commit b10e472

Browse files
committed
BUGFIX:
- Wait for mission file release on server.stop() to avoid race conditions on upload()
1 parent 232556f commit b10e472

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

core/data/impl/serverimpl.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,27 @@ async def _terminate(self) -> None:
646646
finally:
647647
self.process = None
648648

649+
@performance_log()
650+
async def stop(self) -> None:
651+
async def wait_for_file_release(timeout: int):
652+
mission_file = self._get_current_mission_file()
653+
if not mission_file:
654+
return
655+
for i in range(0, timeout * 2):
656+
try:
657+
with open(mission_file, mode='a'):
658+
return
659+
except PermissionError:
660+
await asyncio.sleep(0.5)
661+
else:
662+
raise TimeoutError()
663+
664+
if self.status in [Status.PAUSED, Status.RUNNING]:
665+
timeout = 120 if self.node.locals.get('slow_system', False) else 60
666+
await self.send_to_dcs({"command": "stop_server"})
667+
await self.wait_for_status_change([Status.STOPPED], timeout)
668+
await wait_for_file_release(10)
669+
649670
@performance_log()
650671
async def apply_mission_changes(self, filename: Optional[str] = None) -> str:
651672
# disable autoscan

core/data/proxy/serverproxy.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,15 @@ async def shutdown(self, force: bool = False) -> None:
111111
}, node=self.node.name, timeout=timeout)
112112
self.status = Status.SHUTDOWN
113113

114+
async def stop(self) -> None:
115+
timeout = 180 if not self.node.slow_system else 300
116+
await self.bus.send_to_node_sync({
117+
"command": "rpc",
118+
"object": "Server",
119+
"method": "stop",
120+
"server_name": self.name
121+
}, node=self.node.name, timeout=timeout)
122+
114123
async def init_extensions(self) -> list[str]:
115124
timeout = 180 if not self.node.slow_system else 300
116125
data = await self.bus.send_to_node_sync({

core/data/server.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,12 +313,8 @@ async def playSound(self, recipient: Union[Coalition, str], sound: str):
313313
"sound": sound
314314
})
315315

316-
@performance_log()
317316
async def stop(self) -> None:
318-
if self.status in [Status.PAUSED, Status.RUNNING]:
319-
timeout = 120 if self.node.locals.get('slow_system', False) else 60
320-
await self.send_to_dcs({"command": "stop_server"})
321-
await self.wait_for_status_change([Status.STOPPED], timeout)
317+
raise NotImplemented()
322318

323319
@performance_log()
324320
async def start(self) -> bool:

0 commit comments

Comments
 (0)