motorcortex-python 1.0.2__py3-none-any.whl → 1.0.3__py3-none-any.whl

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.
motorcortex/__init__.py CHANGED
@@ -181,6 +181,14 @@ def makeUrl(address: str, port: int | None) -> str:
181
181
  return address
182
182
 
183
183
 
184
+ # Bound for the session-management RPCs issued from the reconnect path
185
+ # (restoreSession, fallback login). Any finite value prevents the
186
+ # state-callback worker from blocking forever on a reply that never
187
+ # arrives (e.g. the redial landed on a reverse proxy before the engine
188
+ # behind it was ready); 5 s is ~1000x a normal RPC round-trip.
189
+ _SESSION_RPC_TIMEOUT_MS = 5000
190
+
191
+
184
192
  def _reconnect_state_update(
185
193
  req: Any, sub: Any, state: "ConnectionState", *,
186
194
  motorcortex_types: "MessageTypes",
@@ -212,11 +220,11 @@ def _reconnect_state_update(
212
220
  return
213
221
 
214
222
  restored = False
223
+ motorcortex_msg = motorcortex_types.motorcortex()
215
224
  if req.token:
216
225
  try:
217
226
  restore_reply = req.restoreSession(req.token)
218
- restore_msg = restore_reply.get(timeout_ms=5000)
219
- motorcortex_msg = motorcortex_types.motorcortex()
227
+ restore_msg = restore_reply.get(timeout_ms=_SESSION_RPC_TIMEOUT_MS)
220
228
  if restore_msg and restore_msg.status == motorcortex_msg.OK:
221
229
  restored = True
222
230
  logger.debug("[SESSION] Session restored using token")
@@ -225,7 +233,29 @@ def _reconnect_state_update(
225
233
 
226
234
  if not restored:
227
235
  logger.debug("[SESSION] Falling back to login")
228
- req.login(login, password).get()
236
+ # Guarded like restoreSession above: an unanswered or rejected
237
+ # login must not wedge the state-callback worker (Reply.get()
238
+ # without a timeout waits forever) nor leave the token-refresh
239
+ # timer polling a dead session ("requested session token but is
240
+ # not logged in" every 30 s). On failure: stop the timer, bail
241
+ # out, and let the next CONNECTION_OK edge retry the re-auth.
242
+ try:
243
+ login_msg = req.login(login, password).get(timeout_ms=_SESSION_RPC_TIMEOUT_MS)
244
+ if not login_msg or login_msg.status != motorcortex_msg.OK:
245
+ logger.warning(
246
+ "[SESSION] Re-login after reconnect failed (status %s); "
247
+ "will retry on next reconnect",
248
+ getattr(login_msg, "status", None),
249
+ )
250
+ req._stopTokenRefresh()
251
+ return
252
+ except Exception as e:
253
+ logger.warning(
254
+ "[SESSION] Re-login after reconnect failed: %s; "
255
+ "will retry on next reconnect", e,
256
+ )
257
+ req._stopTokenRefresh()
258
+ return
229
259
 
230
260
  req._startTokenRefresh(token_interval_sec)
231
261
  sub.resubscribe()
motorcortex/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = '1.0.2'
1
+ __version__ = '1.0.3'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: motorcortex-python
3
- Version: 1.0.2
3
+ Version: 1.0.3
4
4
  Summary: Python bindings for Motorcortex Engine
5
5
  Home-page: https://www.motorcortex.io
6
6
  Author: Alexey Zakharov
@@ -1,4 +1,4 @@
1
- motorcortex/__init__.py,sha256=eVuJIbn8gj549T1HZ7JKZ1i4gx0aibuOLJ-apB6CO3g,15204
1
+ motorcortex/__init__.py,sha256=o-xtJGJvQvFWgbsY7HfqmXBov0RlDEhrwGdwwYyK514,16691
2
2
  motorcortex/_connection_state.py,sha256=0jos75PAyMsN3ew6HRoRDbLY-lGCzDit-SiUR7ZvnlA,2203
3
3
  motorcortex/_request_builders.py,sha256=ZP-WKS56CkrpoKbpU6FEM5e5E_MAr_P2PEQPZYaS5ls,5265
4
4
  motorcortex/_request_utils.py,sha256=K8UCqgDx7DenZlY-l8zEqowIM0yiVPuLciTy9KX5wBY,12155
@@ -20,9 +20,9 @@ motorcortex/state_callback_handler.py,sha256=Vr9XZ5vN7-CKJdvbJlFkenwH6JfhuInkM1R
20
20
  motorcortex/subscribe.py,sha256=E4Hz03vF2Jgk1vXqhHf42Rd-y337Rt78zY70X2NrXeo,15755
21
21
  motorcortex/subscription.py,sha256=UTPmLOl41Tn3mRl3Hyam2R9bCg9D5y5EJsiChYERu5E,15425
22
22
  motorcortex/timespec.py,sha256=bZ-CD2EY0ALoWmJyluThxkiqfVCiGZqPPHRlKSvq7Fs,4573
23
- motorcortex/version.py,sha256=ZTipNH6wyC6qsq1H_lZsvJyVruUa1nu3y4EysMdkpuU,22
24
- motorcortex_python-1.0.2.dist-info/LICENSE,sha256=m5IaPTxipQwDCpY_YUD927y5QnUzqKGLVUY8E2KxDMk,1165
25
- motorcortex_python-1.0.2.dist-info/METADATA,sha256=ghM1WccanWR1oyGtsvnIW67hrU1QK2Y1fq5KjfaWjqA,6141
26
- motorcortex_python-1.0.2.dist-info/WHEEL,sha256=51RkbunBAw4BWsgaQWTpPhg4Diwp3c9P5iaLk67Hdtg,92
27
- motorcortex_python-1.0.2.dist-info/top_level.txt,sha256=2Glsldo3S13fGB0ub_vogd7y-RQYYNXDjnm-qESmjBY,12
28
- motorcortex_python-1.0.2.dist-info/RECORD,,
23
+ motorcortex/version.py,sha256=qKK4BMzdt84HiCorJPWqgEfa_DbJeuGx_bIPrDui2vc,22
24
+ motorcortex_python-1.0.3.dist-info/LICENSE,sha256=m5IaPTxipQwDCpY_YUD927y5QnUzqKGLVUY8E2KxDMk,1165
25
+ motorcortex_python-1.0.3.dist-info/METADATA,sha256=0IDEK8pY81NIQIiMFL_8xXIXZe2N_wh5Jc60HfjgMTw,6141
26
+ motorcortex_python-1.0.3.dist-info/WHEEL,sha256=51RkbunBAw4BWsgaQWTpPhg4Diwp3c9P5iaLk67Hdtg,92
27
+ motorcortex_python-1.0.3.dist-info/top_level.txt,sha256=2Glsldo3S13fGB0ub_vogd7y-RQYYNXDjnm-qESmjBY,12
28
+ motorcortex_python-1.0.3.dist-info/RECORD,,