Skip to content

Crashes with HTML/plugin async operations #63

@zenibako

Description

@zenibako

I am using an HTML window to send and receive WebSocket messages:

  • My plugin is iterating over a list of messages generated from lines in the script.
  • Messages are sent in bundles to the WS client inside the HTML window using window.runJS(...).
  • Replies are returned to the plugin with Beat.call((arg) => Beat.custom.handleReply(JSON.stringify(arg)), reply).

The problem appears to be:

  • When I iterate over bundles with messages that expect a reply (using a Promise to wait for each bundle to get a reply), the plugin crashes.
  • Based on logs, it happens when the window calls the custom function handleReply for only the last iteration.
  • If there are multiple bundles, all the bundles process properly (with logs) except for the last one.
  • In all cases, the window successfully receives sent messages. The issue is only on the reply back to the Beat window.
  • This issue doesn't happen when I send the initial message to establish the connection to the WebSocket server, which is a single message with a reply.

Initially, I thought it had to do with my Promise management, but my Jest tests don't have a problem; it only has an issue when I'm running it in the live Beat app.

Also, I tried using Beat.async() and Beat.sync() as suggested in the wiki, and that doesn't impact the behavior.

Is there a best practice for using Promises in the plugin and waiting for iterations to be fulfilled, especially in regards to interacting back and forth with the window?

FYI, I am launching the function from the menu, which is mounted after the initial connection is made.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions