Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange things are happening in packed electron environment #133

Closed
hrueger opened this issue Dec 1, 2022 · 10 comments
Closed

Strange things are happening in packed electron environment #133

hrueger opened this issue Dec 1, 2022 · 10 comments

Comments

@hrueger
Copy link

hrueger commented Dec 1, 2022

  • I'm submitting a ...
    [x] bug report
    [ ] feature request
    [ ] question about the decisions made in the repository
    [ ] question about how to use this project

  • Summary

Hi all,
I just ran into a very strange problem. The ATEM functionality in my application is working, if i start it in dev mode (using node or electron does not matter). However, when it is packed (using electron-builder), the promise of the atem.connect() method never resolves nor rejects.
To me, that sounds like a problem with the libraries being packed into an asar file, so I went ahead and added the following libraries to asarUnpack:

node_modules/threadedclass, node_modules/atem-connection, node_modules/wavefile, node_modules/exit-hook, node_modules/is-running, node_modules/p-queue, node_modules/p-timeout, node_modules/p-finally, node_modules/p-lazy, node_modules/@julusian/freetype2

However, this does not change anything.

Even more strange things:
I got lots of crash reports with the following error:

Uncaught Error (but reported silently): Unhandled error. (<ref *1> {
  id: 'process_9561_0',
  isNamed: false,
  pathToWorker: 'C:\\Program Files\\Glue\\resources\\app.asar\\node_modules\\threadedclass\\dist\\child-process\\threadedclass-worker.js',
  process: WorkerThread {
    _events: E... {
  originalException: Error [ERR_UNHANDLED_ERROR]: Unhandled error. (<ref *1> {
    id: 'process_9561_0',
    isNamed: false,
    pathToWorker: 'C:\\Program Files\\Glue\\resources\\app.asar\\node_modules\\threadedclass\\dist\\child-process\\threadedclass-worker.js',
    process: WorkerThread {
      _events: Events <[Object: null prototype] {}> {
        close: [EE],
        error: [EE],
        message: [EE]
      },
      _eventsCount: 3,
      _isFakeProcess: false,
      worker: Worker {
        _events: [Object: null prototype],
        _eventsCount: 7,
        _maxListeners: undefined,
        performance: [Object],
        [Symbol(kCapture)]: false,
        [Symbol(kHandle)]: [Worker],
        [Symbol(kPort)]: [MessagePort [EventTarget]],
        [Symbol(kParentSideStdio)]: [Object],
        [Symbol(kPublicPort)]: [MessagePort [EventTarget]],
        [Symbol(kNewListener)]: [Function (anonymous)],
        [Symbol(kRemoveListener)]: [Function (anonymous)],
        [Symbol(kLoopStartTime)]: -1,
        [Symbol(kIsOnline)]: true
      }
    },
    usage: 1,
    instances: {
      'instance_9561_0_atem-connection': {
        id: 'instance_9561_0_atem-connection',
        child: [Circular *1],
        proxy: {},
        usage: undefined,
        freezeLimit: 600,
        onMessageCallback: [Function: onMessageFromInstance],
        pathToModule: 'C:\\Program Files\\Glue\\resources\\app.asar\\node_modules\\atem-connection\\dist\\lib\\atemSocketChild.js',
        exportName: 'AtemSocketChild',
        constructorArgs: [Array],
        initialized: true,
        config: [Object]
      }
    },
    methods: {},
    alive: true,
    isClosing: false,
    config: {
      instanceName: 'atem-connection',
      freezeLimit: 600,
      autoRestart: true,
      disableMultithreading: false
    },
    cmdId: 2,
    instanceMessageQueue: { '0': [Function (anonymous)], '1': [Function (anonymous)] },
    childMessageQueue: {},
    callbackId: 0,
    callbacks: {
      '0': [AsyncFunction (anonymous)],
      '1': [AsyncFunction (anonymous)],
      '2': [AsyncFunction (anonymous)],
      '3': [AsyncFunction (anonymous)]
    }
  })
      at new NodeError (node:internal/errors:372:5)
      at ThreadedClassManagerClassInternal.emit (node:events:516:17)
      at ThreadedClassManagerClassInternal.emit (node:domain:475:12)
      at WorkerThread.<anonymous> (C:\Program Files\Glue\resources\app.asar\node_modules\threadedclass\dist\parent-process\manager.js:637:18)
      at WorkerThread.emit (C:\Program Files\Glue\resources\app.asar\node_modules\eventemitter3\index.js:181:35)
      at Worker.<anonymous> (C:\Program Files\Glue\resources\app.asar\node_modules\threadedclass\dist\parent-process\workerPlatform\workerThreads.js:48:18)
      at Worker.emit (node:events:527:28)
      at Worker.emit (node:domain:475:12)
      at [kOnErrorMessage] (node:internal/worker:290:10)
      at [kOnMessage] (node:internal/worker:301:37) {
    code: 'ERR_UNHANDLED_ERROR',
    context: {
      id: 'process_9561_0',
      isNamed: false,
      pathToWorker: 'C:\\Program Files\\Glue\\resources\\app.asar\\node_modules\\threadedclass\\dist\\child-process\\threadedclass-worker.js',
      process: [WorkerThread],
      usage: 1,
      instances: [Object],
      methods: {},
      alive: true,
      isClosing: false,
      config: [Object],
      cmdId: 3,
      instanceMessageQueue: [Object],
      childMessageQueue: {},
      callbackId: 0,
      callbacks: [Object]
    }
  }
}

However, I could only reproduce that error on my machine once and not anymore (?).

Do you have any clue what could be the problem? It's probably not my bundler (esbuild) as (I) I've marked all packages as external and (II) it works if started with electron dist/index.ts.

  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)

I'm using "atem-connection": "3.1.2" and "electron": "20.3.8".

The only idea I have is going back version by version until it works again and then trying to figure out what has changed.

@hrueger
Copy link
Author

hrueger commented Dec 2, 2022

One more thing: I also get lots of those errors after the error above:

Uncaught Error (but reported silently): Timeout when trying to restart after 1000 {
  originalException: 'Timeout when trying to restart after 1000',
  syntheticException: Error: Timeout when trying to restart after 1000
      at Hub.captureException (C:\Program Files\Glue\resources\app.asar\node_modules\@sentry\hub\cjs\hub.js:131:30)
      at Object.captureException (C:\Program Files\Glue\resources\app.asar\node_modules\@sentry\hub\cjs\exports.js:20:30)
      at process.<anonymous> (C:\Program Files\Glue\resources\app.asar\dist\index.js:41:25801)
      at process.emit (node:events:539:35)
      at process.emit (node:domain:475:12)
      at emit (node:internal/process/promises:140:20)
      at processPromiseRejections (node:internal/process/promises:269:11)
      at processTicksAndRejections (node:internal/process/task_queues:97:32)
      at runNextTicks (node:internal/process/task_queues:65:3)
      at process.processTimers (node:internal/timers:499:9),
  captureContext: undefined,
  event_id: 'af7edbbd7f4d40f1913b071131da10db'
}
This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason:
Timeout when trying to restart after 1000
(node:9088) UnhandledPromiseRejectionWarning: Timeout when trying to restart after 1000
(node:9088) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 5)

I'm not sure if they also come from atem-connection or from sentry, but maybe it's a hint.

@hrueger
Copy link
Author

hrueger commented Dec 2, 2022

It works fine when packed if I use disableMultithreaded: true in the constructor options, which I guess makes sense.
Maybe we should move this issue to the threadedclass repo?

Currently trying to find out why the connect promise never resolves nor rejects.

@hrueger
Copy link
Author

hrueger commented Dec 2, 2022

I'm just gonna post this here too (as I'm still not sure whether it's a bug of threadedclass or of its usage in atem-connection:

Although I didn't expect that to also happen in a minimal sample with just the atem-connection library, I was actually able to create a reproduction with less then 20 lines of code:
https://github.com/hrueger/threadedclass-issue-74
I hope that helps!

@Julusian
Copy link
Member

Julusian commented Dec 2, 2022

Have you looked at what companion is going? That is using v3.1.2 of atem-connection and noone has reported any issues with it

@hrueger
Copy link
Author

hrueger commented Dec 2, 2022

Good idea.
Maybe it is connected to some dependency update, like electron or electron-builder. I know that it was working for me until a couple of versions ago. It's just hard to find what makes the difference in a diff of more than 300 commits ;-)

I noticed that companion is using electron 13. I'll try with that one.

@hrueger
Copy link
Author

hrueger commented Dec 2, 2022

This seems to be the right direction! It's working with electron@13.6.9.
However, downgrading to this is unfortunately not possible for me. I'll try and find the exact version where it breaks. I believe I've been using electron@17 until recently when I upgraded to electron@20.

Edit: Maybe it's a fault of electron-builder. Will check that later today.

@Julusian
Copy link
Member

Julusian commented Dec 2, 2022

The electron version sounds like a strange this to break it, but its possible...
threadedclass sounds more likely to me, or electron-builder

@hrueger
Copy link
Author

hrueger commented Dec 2, 2022

electron-builder is probably not the issue, as the comination electron@13 and electron-builder@23.6.0 works.

@hrueger
Copy link
Author

hrueger commented Dec 2, 2022

Continuing at nytamin/threadedClass#74

@hrueger
Copy link
Author

hrueger commented Dec 5, 2022

Closing this as it is definitely not a problem of atem-connection.

@hrueger hrueger closed this as completed Dec 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants