@scrypted/server 0.7.10 → 0.7.12

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.

Potentially problematic release.


This version of @scrypted/server might be problematic. Click here for more details.

package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scrypted/server",
3
- "version": "0.7.10",
3
+ "version": "0.7.12",
4
4
  "description": "",
5
5
  "dependencies": {
6
6
  "@mapbox/node-pre-gyp": "^1.0.10",
@@ -488,6 +488,11 @@ class PluginRemote:
488
488
  reader = StreamPipeReader(parent_conn)
489
489
  forkPeer, readLoop = await rpc_reader.prepare_peer_readloop(self.loop, reader = reader, writeFd = parent_conn.fileno())
490
490
  forkPeer.peerName = 'thread'
491
+
492
+ async def updateStats(stats):
493
+ allMemoryStats[forkPeer] = stats
494
+ forkPeer.params['updateStats'] = updateStats
495
+
491
496
  async def forkReadLoop():
492
497
  try:
493
498
  await readLoop()
@@ -495,6 +500,7 @@ class PluginRemote:
495
500
  # traceback.print_exc()
496
501
  print('fork read loop exited')
497
502
  finally:
503
+ allMemoryStats.pop(forkPeer)
498
504
  parent_conn.close()
499
505
  reader.executor.shutdown()
500
506
  asyncio.run_coroutine_threadsafe(forkReadLoop(), loop=self.loop)
@@ -585,6 +591,9 @@ class PluginRemote:
585
591
  async def getServicePort(self, name):
586
592
  pass
587
593
 
594
+
595
+ allMemoryStats = {}
596
+
588
597
  async def plugin_async_main(loop: AbstractEventLoop, readFd: int = None, writeFd: int = None, reader: asyncio.StreamReader = None, writer: asyncio.StreamWriter = None):
589
598
  peer, readLoop = await rpc_reader.prepare_peer_readloop(loop, readFd=readFd, writeFd=writeFd, reader=reader, writer=writer)
590
599
  peer.params['print'] = print
@@ -593,6 +602,7 @@ async def plugin_async_main(loop: AbstractEventLoop, readFd: int = None, writeFd
593
602
  async def get_update_stats():
594
603
  update_stats = await peer.getParam('updateStats')
595
604
  if not update_stats:
605
+ print('host did not provide update_stats')
596
606
  return
597
607
 
598
608
  def stats_runner():
@@ -608,8 +618,12 @@ async def plugin_async_main(loop: AbstractEventLoop, readFd: int = None, writeFd
608
618
  resource.RUSAGE_SELF).ru_maxrss
609
619
  except:
610
620
  heapTotal = 0
621
+
622
+ for _, stats in allMemoryStats.items():
623
+ ptime += stats['cpu']['user']
624
+ heapTotal += stats['memoryUsage']['heapTotal']
625
+
611
626
  stats = {
612
- 'type': 'stats',
613
627
  'cpu': {
614
628
  'user': ptime,
615
629
  'system': 0,
package/python/rpc.py CHANGED
@@ -29,6 +29,8 @@ class RPCResultError(Exception):
29
29
  def __init__(self, caught, message):
30
30
  self.caught = caught
31
31
  self.message = message
32
+ self.name = None
33
+ self.stack = None
32
34
 
33
35
 
34
36
  class RpcSerializer:
@@ -121,6 +123,16 @@ class RpcPeer:
121
123
  self.killed = False
122
124
 
123
125
  def __apply__(self, proxyId: str, oneWayMethods: List[str], method: str, args: list):
126
+ oneway = oneWayMethods and method in oneWayMethods
127
+
128
+ if self.killed:
129
+ future = Future()
130
+ if oneway:
131
+ future.set_result(None)
132
+ return future
133
+ future.set_exception(RPCResultError(None, 'RpcPeer has been killed (apply) ' + str(method)))
134
+ return future
135
+
124
136
  serializationContext: Dict = {}
125
137
  serializedArgs = []
126
138
  for arg in args:
@@ -134,7 +146,7 @@ class RpcPeer:
134
146
  'method': method,
135
147
  }
136
148
 
137
- if oneWayMethods and method in oneWayMethods:
149
+ if oneway:
138
150
  rpcApply['oneway'] = True
139
151
  self.send(rpcApply, None, serializationContext)
140
152
  future = Future()
@@ -472,12 +484,13 @@ class RpcPeer:
472
484
  pass
473
485
 
474
486
  async def createPendingResult(self, cb: Callable[[str, Callable[[Exception], None]], None]):
475
- # if (Object.isFrozen(this.pendingResults))
476
- # return Promise.reject(new RPCResultError('RpcPeer has been killed'));
487
+ future = Future()
488
+ if self.killed:
489
+ future.set_exception(RPCResultError(None, 'RpcPeer has been killed (createPendingResult)'))
490
+ return future
477
491
 
478
492
  id = str(self.idCounter)
479
493
  self.idCounter = self.idCounter + 1
480
- future = Future()
481
494
  self.pendingResults[id] = future
482
495
  await cb(id, lambda e: future.set_exception(RPCResultError(e, None)))
483
496
  return await future