@riddix/hamh 2.1.0-alpha.518 → 2.1.0-alpha.520

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -166866,7 +166866,7 @@ function ensureCommissioningConfig(server) {
166866
166866
 
166867
166867
  // src/services/bridges/bridge.ts
166868
166868
  var AUTO_FORCE_SYNC_INTERVAL_MS = 9e4;
166869
- var DEAD_SESSION_TIMEOUT_MS = 3 * 60 * 1e3;
166869
+ var DEAD_SESSION_TIMEOUT_MS = 6e4;
166870
166870
  var Bridge = class {
166871
166871
  constructor(env, logger203, dataProvider, endpointManager) {
166872
166872
  this.dataProvider = dataProvider;
@@ -166890,6 +166890,7 @@ var Bridge = class {
166890
166890
  onStatusChange;
166891
166891
  autoForceSyncTimer = null;
166892
166892
  deadSessionTimer = null;
166893
+ staleSessionTimers = /* @__PURE__ */ new Map();
166893
166894
  // Tracks the last synced state JSON per entity to avoid pushing unchanged states.
166894
166895
  // Key: entity_id, Value: JSON.stringify of entity.state
166895
166896
  lastSyncedStates = /* @__PURE__ */ new Map();
@@ -167082,6 +167083,18 @@ ${e?.toString()}`);
167082
167083
  "Subscriptions recovered, canceled dead session cleanup"
167083
167084
  );
167084
167085
  }
167086
+ if (session.subscriptions.size === 0 && !this.staleSessionTimers.has(session.id)) {
167087
+ this.staleSessionTimers.set(
167088
+ session.id,
167089
+ setTimeout(() => {
167090
+ this.staleSessionTimers.delete(session.id);
167091
+ this.closeStaleSession(session.id);
167092
+ }, DEAD_SESSION_TIMEOUT_MS)
167093
+ );
167094
+ } else if (session.subscriptions.size > 0 && this.staleSessionTimers.has(session.id)) {
167095
+ clearTimeout(this.staleSessionTimers.get(session.id));
167096
+ this.staleSessionTimers.delete(session.id);
167097
+ }
167085
167098
  };
167086
167099
  sessionManager.subscriptionsChanged.on(this.sessionDiagHandler);
167087
167100
  this.sessionAddedHandler = (newSession) => {
@@ -167109,6 +167122,24 @@ ${e?.toString()}`);
167109
167122
  } catch {
167110
167123
  }
167111
167124
  }
167125
+ closeStaleSession(sessionId) {
167126
+ try {
167127
+ const sessionManager = this.server.env.get(SessionManager);
167128
+ for (const s of [...sessionManager.sessions]) {
167129
+ if (s.id === sessionId && !s.isClosing && s.subscriptions.size === 0) {
167130
+ this.log.warn(
167131
+ `Closing stale session ${s.id} (peer ${s.peerNodeId}, no subscriptions for ${DEAD_SESSION_TIMEOUT_MS / 1e3}s)`
167132
+ );
167133
+ s.initiateClose().catch(() => {
167134
+ s.initiateForceClose().catch(() => {
167135
+ });
167136
+ });
167137
+ break;
167138
+ }
167139
+ }
167140
+ } catch {
167141
+ }
167142
+ }
167112
167143
  closeDeadSessions() {
167113
167144
  try {
167114
167145
  const sessionManager = this.server.env.get(SessionManager);
@@ -167116,9 +167147,11 @@ ${e?.toString()}`);
167116
167147
  for (const s of sessions) {
167117
167148
  if (!s.isClosing && s.subscriptions.size === 0) {
167118
167149
  this.log.warn(
167119
- `Force-closing dead session ${s.id} (peer ${s.peerNodeId}, no subscriptions for ${DEAD_SESSION_TIMEOUT_MS / 1e3}s)`
167150
+ `Closing dead session ${s.id} (peer ${s.peerNodeId}, no subscriptions for ${DEAD_SESSION_TIMEOUT_MS / 1e3}s)`
167120
167151
  );
167121
- s.initiateForceClose().catch(() => {
167152
+ s.initiateClose().catch(() => {
167153
+ s.initiateForceClose().catch(() => {
167154
+ });
167122
167155
  });
167123
167156
  }
167124
167157
  }
@@ -167146,6 +167179,10 @@ ${e?.toString()}`);
167146
167179
  clearTimeout(this.deadSessionTimer);
167147
167180
  this.deadSessionTimer = null;
167148
167181
  }
167182
+ for (const timer of this.staleSessionTimers.values()) {
167183
+ clearTimeout(timer);
167184
+ }
167185
+ this.staleSessionTimers.clear();
167149
167186
  }
167150
167187
  stopAutoForceSync() {
167151
167188
  if (this.autoForceSyncTimer) {
@@ -179545,7 +179582,7 @@ function hashAreaId(areaId) {
179545
179582
  // src/services/bridges/server-mode-bridge.ts
179546
179583
  init_dist();
179547
179584
  var AUTO_FORCE_SYNC_INTERVAL_MS2 = 9e4;
179548
- var DEAD_SESSION_TIMEOUT_MS2 = 3 * 60 * 1e3;
179585
+ var DEAD_SESSION_TIMEOUT_MS2 = 6e4;
179549
179586
  var ServerModeBridge = class {
179550
179587
  constructor(logger203, dataProvider, endpointManager, server) {
179551
179588
  this.dataProvider = dataProvider;
@@ -179563,6 +179600,7 @@ var ServerModeBridge = class {
179563
179600
  onStatusChange;
179564
179601
  autoForceSyncTimer = null;
179565
179602
  deadSessionTimer = null;
179603
+ staleSessionTimers = /* @__PURE__ */ new Map();
179566
179604
  warmStartTimer = null;
179567
179605
  // Tracks the last synced state JSON per entity to avoid pushing unchanged states.
179568
179606
  lastSyncedState;
@@ -179760,6 +179798,18 @@ ${e?.toString()}`);
179760
179798
  "Subscriptions recovered, canceled dead session cleanup"
179761
179799
  );
179762
179800
  }
179801
+ if (session.subscriptions.size === 0 && !this.staleSessionTimers.has(session.id)) {
179802
+ this.staleSessionTimers.set(
179803
+ session.id,
179804
+ setTimeout(() => {
179805
+ this.staleSessionTimers.delete(session.id);
179806
+ this.closeStaleSession(session.id);
179807
+ }, DEAD_SESSION_TIMEOUT_MS2)
179808
+ );
179809
+ } else if (session.subscriptions.size > 0 && this.staleSessionTimers.has(session.id)) {
179810
+ clearTimeout(this.staleSessionTimers.get(session.id));
179811
+ this.staleSessionTimers.delete(session.id);
179812
+ }
179763
179813
  };
179764
179814
  sessionManager.subscriptionsChanged.on(this.sessionDiagHandler);
179765
179815
  this.sessionAddedHandler = (newSession) => {
@@ -179787,6 +179837,24 @@ ${e?.toString()}`);
179787
179837
  } catch {
179788
179838
  }
179789
179839
  }
179840
+ closeStaleSession(sessionId) {
179841
+ try {
179842
+ const sessionManager = this.server.env.get(SessionManager);
179843
+ for (const s of [...sessionManager.sessions]) {
179844
+ if (s.id === sessionId && !s.isClosing && s.subscriptions.size === 0) {
179845
+ this.log.warn(
179846
+ `Closing stale session ${s.id} (peer ${s.peerNodeId}, no subscriptions for ${DEAD_SESSION_TIMEOUT_MS2 / 1e3}s)`
179847
+ );
179848
+ s.initiateClose().catch(() => {
179849
+ s.initiateForceClose().catch(() => {
179850
+ });
179851
+ });
179852
+ break;
179853
+ }
179854
+ }
179855
+ } catch {
179856
+ }
179857
+ }
179790
179858
  closeDeadSessions() {
179791
179859
  try {
179792
179860
  const sessionManager = this.server.env.get(SessionManager);
@@ -179794,9 +179862,11 @@ ${e?.toString()}`);
179794
179862
  for (const s of sessions) {
179795
179863
  if (!s.isClosing && s.subscriptions.size === 0) {
179796
179864
  this.log.warn(
179797
- `Force-closing dead session ${s.id} (peer ${s.peerNodeId}, no subscriptions for ${DEAD_SESSION_TIMEOUT_MS2 / 1e3}s)`
179865
+ `Closing dead session ${s.id} (peer ${s.peerNodeId}, no subscriptions for ${DEAD_SESSION_TIMEOUT_MS2 / 1e3}s)`
179798
179866
  );
179799
- s.initiateForceClose().catch(() => {
179867
+ s.initiateClose().catch(() => {
179868
+ s.initiateForceClose().catch(() => {
179869
+ });
179800
179870
  });
179801
179871
  }
179802
179872
  }
@@ -179824,6 +179894,10 @@ ${e?.toString()}`);
179824
179894
  clearTimeout(this.deadSessionTimer);
179825
179895
  this.deadSessionTimer = null;
179826
179896
  }
179897
+ for (const timer of this.staleSessionTimers.values()) {
179898
+ clearTimeout(timer);
179899
+ }
179900
+ this.staleSessionTimers.clear();
179827
179901
  }
179828
179902
  stopAutoForceSync() {
179829
179903
  if (this.autoForceSyncTimer) {