fix(gateway): write restart markers atomically and fix Windows lock collisions
This commit is contained in:
@@ -239,7 +239,7 @@ sys.path.insert(0, str(Path(__file__).parent.parent))
|
||||
|
||||
# Resolve Hermes home directory (respects HERMES_HOME override)
|
||||
from hermes_constants import get_hermes_home
|
||||
from utils import atomic_yaml_write, base_url_host_matches, is_truthy_value
|
||||
from utils import atomic_json_write, atomic_yaml_write, base_url_host_matches, is_truthy_value
|
||||
_hermes_home = get_hermes_home()
|
||||
|
||||
# Load environment variables from ~/.hermes/.env first.
|
||||
@@ -2245,7 +2245,7 @@ class GatewayRunner:
|
||||
# (they might become active again next restart)
|
||||
|
||||
try:
|
||||
path.write_text(json.dumps(new_counts))
|
||||
atomic_json_write(path, new_counts, indent=None)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@@ -2313,7 +2313,7 @@ class GatewayRunner:
|
||||
if session_key in counts:
|
||||
del counts[session_key]
|
||||
if counts:
|
||||
path.write_text(json.dumps(counts))
|
||||
atomic_json_write(path, counts, indent=None)
|
||||
else:
|
||||
path.unlink(missing_ok=True)
|
||||
except Exception:
|
||||
@@ -6734,8 +6734,10 @@ class GatewayRunner:
|
||||
}
|
||||
if event.source.thread_id:
|
||||
notify_data["thread_id"] = event.source.thread_id
|
||||
(_hermes_home / ".restart_notify.json").write_text(
|
||||
json.dumps(notify_data)
|
||||
atomic_json_write(
|
||||
_hermes_home / ".restart_notify.json",
|
||||
notify_data,
|
||||
indent=None,
|
||||
)
|
||||
except Exception as e:
|
||||
logger.debug("Failed to write restart notify file: %s", e)
|
||||
@@ -6752,8 +6754,10 @@ class GatewayRunner:
|
||||
}
|
||||
if event.platform_update_id is not None:
|
||||
dedup_data["update_id"] = event.platform_update_id
|
||||
(_hermes_home / ".restart_last_processed.json").write_text(
|
||||
json.dumps(dedup_data)
|
||||
atomic_json_write(
|
||||
_hermes_home / ".restart_last_processed.json",
|
||||
dedup_data,
|
||||
indent=None,
|
||||
)
|
||||
except Exception as e:
|
||||
logger.debug("Failed to write restart dedup marker: %s", e)
|
||||
|
||||
Reference in New Issue
Block a user