nrkno / sofie-emberplus-connection

Ember+ Connection: A Part of the Sofie TV Studio Automation System
https://github.com/nrkno/Sofie-TV-automation/
MIT License
20 stars 15 forks source link

await (await EmberClient.getDirectory(node)).response returns expanded node after "request timeout" error #32

Closed dewiweb closed 11 months ago

dewiweb commented 1 year ago

With this part of code :

if (currOpt_class == "NODE") {
              let childrenArray = [];
              let expandReq = await eGet.getElementByPath(
                parentPath.toString()
              );
              console.log("🚀 : file: main.js:1178 : == : expandReq:", expandReq)
              let getDir = await eGet.getDirectory(expandReq);
              try {
                let getDirResponse = await getDir.response  
              } catch (error) {
                console.log("🚀 : file: main.js:1183 : == : error:", error)

              }
              let nodeChildren = Object.keys(expandReq.children);
              for (i = 0; i < nodeChildren.length; i++) {
                let newChild = await eGet.getElementByPath(
                  parentPath + "." + nodeChildren[i]
                );
                contents = newChild.contents;
                number = newChild.number;
                base_path = { contents, number };
                childrenArray.push(base_path);
              }
              win.webContents.send(
                "expandedNode",
                selectID,
                parentPath,
                childrenArray
              );
              win.webContents.send("expandedElement", expandReq, false);

                console.log("🚀 : file: main.js:1204 : == : childrenArray:", childrenArray)
            }

I tried to list all children of a node. It works well with Lawo Ember+ nodes but with 2 nodes of a Riedel Ember+ tree it returns a "request timeout" error before returning expanded (Frames and Parameters nodes):

12:43:59 / ƒÜÇ : file: main.js:1178 : == : expandReq: {
  contents: { identifier: 'frames', description: 'Frames', type: 'NODE' },
  parent: {
    contents: {
      identifier: 'mediornet',
      description: 'MediorNet',
      isOnline: true,
      type: 'NODE'
    },
    children: [
      null,     [Object],
      [Object], [Object],
      [Object], [Object],
      [Object]
    ],
    number: 1
  },
  path: '1.3',
  number: 3
}
12:44:13 / ƒÜÇ : file: main.js:1183 : == : error: Error: Request timed out
    at C:\Users\Administrateur\Documents\GitHub\MCxOSCnext\node_modules\emberplus-connection\dist\Ember\Client\index.js:525:32
    at Map.forEach (<anonymous>)
    at EmberClient._resendTimer (C:\Users\Administrateur\Documents\GitHub\MCxOSCnext\node_modules\emberplus-connection\dist\Ember\Client\index.js:512:28)
    at Timeout._onTimeout (C:\Users\Administrateur\Documents\GitHub\MCxOSCnext\node_modules\emberplus-connection\dist\Ember\Client\index.js:47:46)
    at listOnTimeout (node:internal/timers:564:17)
    at process.processTimers (node:internal/timers:507:7)
12:44:13 / ƒÜÇ : file: main.js:1204 : == : childrenArray: [
  {
    contents: {
      identifier: 'node_126935767',
      description: 'Node 126935767',
      isOnline: true,
      type: 'NODE'
    },
    number: 126935767
  },
  {
    contents: {
      identifier: 'node_223542758',
      description: 'Node 223542758',
      isOnline: true,
      type: 'NODE'
    },
    number: 223542758
  },
  {
    contents: {
      identifier: 'node_232542718',
      description: 'Node 232542718',
      isOnline: true,
      type: 'NODE'
    },
    number: 232542718
  },
  {
    contents: {
      identifier: 'node_232542742',
      description: 'Node 232542742',
      isOnline: true,
      type: 'NODE'
    },
    number: 232542742
  }
]

You can take a look at my repository https://github.com/dewiweb/MCxOSCnext for a better understanding of this issue(my electron app stucks after this request timeout.

dewiweb commented 1 year ago

I put some logs in _handleIncoming function of "\emberplus-connection\dist\Ember\Client\index.js" file to investigate. Here a console output when I try a Emberclient.getElementByPath("path") with path of riedel's Frames node:

🚀 : file: index.js:328 : EmberClient : _handleIncoming : node: {
  '0': QualifiedElementImpl {
    contents: EmberNodeImpl {
      identifier: 'mediornet',
      description: 'MediorNet',
      isRoot: undefined,
      isOnline: true,
      schemaIdentifiers: undefined,
      templateReference: undefined,
      type: 'NODE'
    },
    children: undefined,
    parent: undefined,
    path: '1'
  }
}
🚀 : file: index.js:342 : EmberClient : _handleIncoming : reqs: [
  {
    reqId: '000b',
    node: NumberedTreeNodeImpl {
      contents: [GetDirectoryImpl],
      children: undefined,
      parent: undefined,
      number: 0
    },
    resolve: [Function (anonymous)],
    reject: [Function (anonymous)],
    message: <Buffer 60 0b 6b 09 a0 07 62 05 a0 03 02 01 20>,
    firstSent: 1681375378929,
    lastSent: 1681375378929
  }
]
🚀 : file: index.js:347 : EmberClient : _handleIncoming : req.resolve 000b
🚀 : file: walkthrough.js:26 : root: NumberedTreeNodeImpl {
  contents: EmberNodeImpl {
    identifier: 'mediornet',
    description: 'MediorNet',
    isRoot: undefined,
    isOnline: true,
    schemaIdentifiers: undefined,
    templateReference: undefined,
    type: 'NODE'
  },
  children: undefined,
  parent: undefined,
  number: 1
}
🚀 : file: index.js:328 : EmberClient : _handleIncoming : node: {
  '0': QualifiedElementImpl {
    contents: EmberNodeImpl {
      identifier: 'productInfo',
      description: 'Product Info',
      isRoot: undefined,
      isOnline: undefined,
      schemaIdentifiers: undefined,
      templateReference: undefined,
      type: 'NODE'
    },
    children: undefined,
    parent: undefined,
    path: '1.1'
  },
  '1': QualifiedElementImpl {
    contents: EmberNodeImpl {
      identifier: 'switchingMatrices',
      description: 'Switching Matrices',
      isRoot: undefined,
      isOnline: undefined,
      schemaIdentifiers: undefined,
      templateReference: undefined,
      type: 'NODE'
    },
    children: undefined,
    parent: undefined,
    path: '1.2'
  },
  '2': QualifiedElementImpl {
    contents: EmberNodeImpl {
      identifier: 'frames',
      description: 'Frames',
      isRoot: undefined,
      isOnline: undefined,
      schemaIdentifiers: undefined,
      templateReference: undefined,
      type: 'NODE'
    },
    children: undefined,
    parent: undefined,
    path: '1.3'
  },
  '3': QualifiedElementImpl {
    contents: EmberNodeImpl {
      identifier: 'functions',
      description: 'Functions',
      isRoot: undefined,
      isOnline: undefined,
      schemaIdentifiers: undefined,
      templateReference: undefined,
      type: 'NODE'
    },
    children: undefined,
    parent: undefined,
    path: '1.4'
  },
  '4': QualifiedElementImpl {
    contents: EmberNodeImpl {
      identifier: 'netParameters',
      description: 'Parameters',
      isRoot: undefined,
      isOnline: undefined,
      schemaIdentifiers: undefined,
      templateReference: undefined,
      type: 'NODE'
    },
    children: undefined,
    parent: undefined,
    path: '1.5'
  },
  '5': QualifiedElementImpl {
    contents: EmberNodeImpl {
      identifier: 'counters',
      description: 'Counters',
      isRoot: undefined,
      isOnline: undefined,
      schemaIdentifiers: undefined,
      templateReference: undefined,
      type: 'NODE'
    },
    children: undefined,
    parent: undefined,
    path: '1.6'
  }
}
🚀 : file: index.js:342 : EmberClient : _handleIncoming : reqs: [
  {
    reqId: '4jn2',
    node: QualifiedElementImpl {
      contents: [EmberNodeImpl],
      children: [Array],
      parent: undefined,
      path: '1'
    },
    resolve: [Function (anonymous)],
    reject: [Function (anonymous)],
    message: <Buffer 60 3b 6b 39 a0 37 6a 35 a0 03 0d 01 01 a1 21 31 1f a0 0b 0c 09 6d 65 64 69 6f 72 6e 65 74 a1 0b 0c 09 4d 65 64 69 6f 72 4e 65 74 a3 03 01 01 ff a2 0b ... 11 more bytes>,
    firstSent: 1681375378944,
    lastSent: 1681375378944
  }
]
🚀 : file: index.js:347 : EmberClient : _handleIncoming : req.resolve 4jn2
🚀 : file: index.js:342 : EmberClient : _handleIncoming : reqs: []
🚀 : file: index.js:342 : EmberClient : _handleIncoming : reqs: []
🚀 : file: index.js:342 : EmberClient : _handleIncoming : reqs: []
🚀 : file: index.js:342 : EmberClient : _handleIncoming : reqs: []
🚀 : file: index.js:342 : EmberClient : _handleIncoming : reqs: []
🚀 : file: index.js:328 : EmberClient : _handleIncoming : node: {
  '0': QualifiedElementImpl {
    contents: EmberNodeImpl {
      identifier: 'node_126935767',
      description: 'Node 126935767',
      isRoot: undefined,
      isOnline: true,
      schemaIdentifiers: undefined,
      templateReference: undefined,
      type: 'NODE'
    },
    children: undefined,
    parent: undefined,
    path: '1.3.126935767'
  },
  '1': QualifiedElementImpl {
    contents: EmberNodeImpl {
      identifier: 'node_223542758',
      description: 'Node 223542758',
      isRoot: undefined,
      isOnline: true,
      schemaIdentifiers: undefined,
      templateReference: undefined,
      type: 'NODE'
    },
    children: undefined,
    parent: undefined,
    path: '1.3.223542758'
  },
  '2': QualifiedElementImpl {
    contents: EmberNodeImpl {
      identifier: 'node_232542718',
      description: 'Node 232542718',
      isRoot: undefined,
      isOnline: true,
      schemaIdentifiers: undefined,
      templateReference: undefined,
      type: 'NODE'
    },
    children: undefined,
    parent: undefined,
    path: '1.3.232542718'
  },
  '3': QualifiedElementImpl {
    contents: EmberNodeImpl {
      identifier: 'node_232542742',
      description: 'Node 232542742',
      isRoot: undefined,
      isOnline: true,
      schemaIdentifiers: undefined,
      templateReference: undefined,
      type: 'NODE'
    },
    children: undefined,
    parent: undefined,
    path: '1.3.232542742'
  }
}
🚀 : file: index.js:342 : EmberClient : _handleIncoming : reqs: []
🚀 : file: index.js:342 : EmberClient : _handleIncoming : reqs: []
🚀 : file: index.js:342 : EmberClient : _handleIncoming : reqs: []
🚀 : file: index.js:342 : EmberClient : _handleIncoming : reqs: []
C:\Users\Administrateur\Documents\GitHub\MCxOSCnext\node_modules\emberplus-connection\dist\Ember\Client\index.js:529
                    req.reject(new Error('Request timed out'));
                               ^

Error: Request timed out
    at C:\Users\Administrateur\Documents\GitHub\MCxOSCnext\node_modules\emberplus-connection\dist\Ember\Client\index.js:529:32
    at Map.forEach (<anonymous>)
    at EmberClient._resendTimer (C:\Users\Administrateur\Documents\GitHub\MCxOSCnext\node_modules\emberplus-connection\dist\Ember\Client\index.js:516:28)
    at Timeout._onTimeout (C:\Users\Administrateur\Documents\GitHub\MCxOSCnext\node_modules\emberplus-connection\dist\Ember\Client\index.js:47:46)
    at listOnTimeout (node:internal/timers:557:17)
    at processTimers (node:internal/timers:500:7)
dewiweb commented 1 year ago

It seems that there an issue in _handleIncoming function :

 : file: index.js:328 : EmberClient : _handleIncoming : node: {
  '0': QualifiedElementImpl {
    contents: EmberNodeImpl {
      identifier: 'node_126935767',
      description: 'Node 126935767',
      isRoot: undefined,
      isOnline: true,
      schemaIdentifiers: undefined,
      templateReference: undefined,
      type: 'NODE'
    },
    children: undefined,
    parent: undefined,
    path: '1.3.126935767'
  },
  '1': QualifiedElementImpl {
    contents: EmberNodeImpl {
      identifier: 'node_223542758',
      description: 'Node 223542758',
      isRoot: undefined,
      isOnline: true,
      schemaIdentifiers: undefined,
      templateReference: undefined,
      type: 'NODE'
    },
    children: undefined,
    parent: undefined,
    path: '1.3.223542758'
  },
  '2': QualifiedElementImpl {
    contents: EmberNodeImpl {
      identifier: 'node_232542718',
      description: 'Node 232542718',
      isRoot: undefined,
      isOnline: true,
      schemaIdentifiers: undefined,
      templateReference: undefined,
      type: 'NODE'
    },
    children: undefined,
    parent: undefined,
    path: '1.3.232542718'
  },
  '3': QualifiedElementImpl {
    contents: EmberNodeImpl {
      identifier: 'node_232542742',
      description: 'Node 232542742',
      isRoot: undefined,
      isOnline: true,
      schemaIdentifiers: undefined,
      templateReference: undefined,
      type: 'NODE'
    },
    children: undefined,
    parent: undefined,
    path: '1.3.232542742'
  }
}
🚀 : file: index.js:333 : EmberClient : _handleIncoming : changes: [
  {
    path: '1.3.1269357',
    node: {
      contents: [EmberNodeImpl],
      children: [Array],
      parent: [NumberedTreeNodeImpl],
      path: '1.3',
      number: 3
    }
  },
  {
    path: '1.3.2235427',
    node: {
      contents: [EmberNodeImpl],
      children: [Array],
      parent: [NumberedTreeNodeImpl],
      path: '1.3',
      number: 3
    }
  },
  {
    path: '1.3.2325427',
    node: {
      contents: [EmberNodeImpl],
      children: [Array],
      parent: [NumberedTreeNodeImpl],
      path: '1.3',
      number: 3
    }
  },
  {
    path: '1.3.2325427',
    node: {
      contents: [EmberNodeImpl],
      children: [Array],
      parent: [NumberedTreeNodeImpl],
      path: '1.3',
      number: 3
    }
  }
]

Node path is OK before :

const changes = this._applyRootToTree(node);

but after it's 2 digits shorter (example ; "1.3.126935767" became "1.3.1269357")??? due to code from line 548 to line 551 of "Ember/Client/index.ts" file :

                                {
                                    path: rootElement.path.substr(0, rootElement.path.length - 2),
                                    node: tree,
                                },
dewiweb commented 1 year ago

resolved (for "Parameters" node but still another unidentified problem with "Frames" node) by replaceing line 546 to 551 with :

const newPath1 = rootElement.path.split('.');
newPath1.length = newPath1.length-1;
let newPath2 = newPath1.join('.') ;
                            changes = [
                                ...changes,
                                {
                                    path: newPath2,
                                    node: tree,
                                },
Julusian commented 11 months ago

Sounds like this has been fixed by #33