emorydunn / StreamDeckPlugin

A library for creating Stream Deck plugins in Swift.
https://emorydunn.github.io/StreamDeckPlugin/
MIT License
50 stars 7 forks source link

Websocket crashes when sending data from the Property Inspector. #7

Closed SENTINELITE closed 2 years ago

SENTINELITE commented 2 years ago

Hey, Emory!

Whenever I open the property inspector from within the StreamDeck interface, the backend plugin crashes, & automatically restarts. After the second opening of the PI, on the same key context, or even two separate contexts, the plugin will crash for ~2 minutes.

I've monitored the console.app's logs for my app streamDeckWSTEST, & I can see the web socket keeps restarting & seeing 'Starting macOS plugin'. As a side note: only sometimes do I see Corpse allowed x of 5.

I'm not really sure if it's something I'm doing or not. It seems to happen with even a minimal project sending to the PI. I've attached some files & crash logs. I'll also attach my current plugin repo, along with the .sdPlugin file, so you can dig a little deeper if need be.

Again, thank you for this VERY helpful plugin!

.ips log

emorydunn commented 2 years ago

Tracking down crashes is really annoying with plugins. Elgato do have some advice for attaching the Xcode debugger, but I've had mixed success with it actually working. Unfortunately I'm not running Monterey, so I can't actually build your project.

Could you provide some examples of any JSON you're sending to the plugin from the PI? At the very least I can throw it into a test and see if it's causing a crash in the event parsing.

SENTINELITE commented 2 years ago

Hey, sorry for the delay! Just got my power back on.

I did try to dig into using the Xcode debugger, but yeah, that's a rough path. 😅

This is what the PI is sending:

{"action":"yat.increment","event":"sendToPlugin","context":"A70B1F417B6372D030BEB3766081C47E","payload":{"type":"updateSettings","shortcutName":"TestAlertDebug","sayHoldTime":"2","sayvoice":"Victoria","isSayvoice":"true"}}

& this is what the Swift plugin in receiving:

Context: 5E2E85220F337A89F07F7A1712EA2342 action: yat.increment payload: ["sayvoice": "Victoria", "isSayvoice": "true", "type": "updateSettings", "shortcutName": "TestAlertDebug", "sayHoldTime": "2"]


Is there anything else I should try to circumvent this? It appears I can open one key, get stuff from the plugin > PI, & send what appears to be an infinite amount of data back to the plugin. When I start opening/changing other keys, usually on that second key, that's were the web socket crashes.

Thanks!

emorydunn commented 2 years ago

I remembered I installed Monterey on an old laptop, and did some testing with both the plugin and repo you linked to, but was unable to reproduce any crashes.

As a proof-of-concept I make a quick version without Combine in an attempt to simplify some of the potential debugging, so maybe give the uncombined branch a test. I've also marked the WS code as public, so you should be able to access some of the underlying URLSessionWebSocketTask.

SENTINELITE commented 2 years ago

Thanks for that! I was able to figure it out. I was accidentally accessing an out of bounds array. Interesting that you couldn't get it to crash. Not really sure why it was out of bounds, but oh well.