bitfocus / companion-module-obs-studio

OBS Studio Module for Companion
MIT License
46 stars 29 forks source link

[BUG] Long delay/hang when loading Companion/changing OBS scene collections #195

Open cattywampus04 opened 1 year ago

cattywampus04 commented 1 year ago

Is this a bug in companion itself or a module?

Is there an existing issue for this?

Describe the bug

Hi,

I have been trying to get OBS updated beyond version 27.2.4. I use various plugins - and it's been a bit of a slog trying to get them working in OBS 28 - which I am to understand is a pretty big revision under the hood.

One of the problems I'm having is with Companion. Version 2.3.1 which I had been using doesn't work with OBS 28, even when using a Websocket 4.9.1 compatibility plugin - the log says I must use Websocket version 5.0.0. Upgrading to version 2.4.1 gets things working again - but there seems to be something different in how Companion is handling sources?

On OBS 27.x and Companion 2.3.1 - I would load things up and everything would be immediately useable. With 2.4.1 and OBS 28, there is an long initial delay before I can use Companion. After some troubleshooting, I found out that on loading Companion, the CPU usage is high - and it stays that way for over 2 minutes on my setup, and the entire time I cannot access the Companion GUI. On a scene collection with no scenes or sources, this initial hang does not happen.

I cloned my scene collection and slowly started removing scenes and sources to see whether there was a specific item that was causing the problem. It turns out that the length of time for Companion to become usable depends how many scenes/sources it has to "enumerate" (can't think of a better word lol). Once it's done it, everything seems to work.

Is this behaviour normal? I've tried to find documentation about it but nothing. I couldn't find any mention of the websockets 4 to 5 either in the change logs.

Thanks

Steps To Reproduce

No response

Expected Behavior

No response

Environment (please complete the following information)

- OS: Windows 10 and 11
- Browser: Chrome
- Companion Version: 2.3.1/2.4.1

Additional context

No response

bryce-seifert commented 1 year ago

For testing purposes, how many scenes/ sources would you say you have in your largest collection?

cattywampus04 commented 1 year ago

Hello,

My scene collection has a lot of scenes/sources. I'd say around ~30 scenes. The number of sources is hard to gauge. If I estimated at 200 I wouldn't know how accurate it would be but it would feel like a number that made sense? I like to create complex scenes. The length of the initial hang/load is commensurate with the number of scenes/sources of the active scene collection. I can switch to a scene collection that has a couple of sources and it the problem vanishes. I can trim down the number of scenes/sources by half, and the hang/load decreases accordingly.

This wasn't an issue with Companion 2.3.1. Companion would just load and be ready for use basically immediately.

One thing I did think I noticed that was different:

With 2.3.1, although there wasn't the initial 2minute, when changing scene in OBS, watching the Companion process in Task Manager would show an increase in CPU utilisation for a brief period. On my system it went to 10% for the Companion process for a second or two, every time the scene changes. With 2.4.1, while there is a slight spike in process CPU usage, it's much less than on 2.3.1.

Could it be that 2.3.1 "enumerates" sources when a scene change happens - which causes more CPU usage every time a scene change happens, whereas 2.4.1 "enumerates" all scenes/sources on load in one bulk session - which in turn causes less CPU load when doing things like scene changes? I am not a developer so this is just a wild guess based on what I see.

Regardless, while I accept that my scenes and sources are complex - a 2+ minute delay when loading Companion is something that would be great to avoid.

Appreciate any help you can offer! Thanks

bryce-seifert commented 1 year ago

Thanks for the info. I'll create a similar project for testing.

One note is that the module was entirely rewritten between 2.3 and 2.4 due to changes with obs-websocket, so that is likely the cause of the different behaviors you're seeing between the two. I'll investigate and see what I can find.

cattywampus04 commented 1 year ago

That's awesome, thanks!

cattywampus04 commented 1 year ago

Hi Bryce,

Please don't take this as me attempting to rush you - am just asking whether it's going to be a short-term or long-term thing you looking into the potential bug I reported?

Just so I can set my expectations!

Thanks again!

bryce-seifert commented 1 year ago

@Stuwot Sorry for not following up with a timeline. It's probably going to be a longer term fix. The main issue is I'm currently working on porting the module for Companion v3, so I'm trying to finish that work before fully addressing this.

Are you open to trying a beta, when I have that ready?

cattywampus04 commented 1 year ago

That's great...and yes I can give the beta try no worries! Thanks again!

bryce-seifert commented 1 year ago

@Stuwot The Companion v3 version of the module is now in the latest beta of Companion. I didn't specifically target this issue yet, but I'm curious if you're able to test and notice any improvements from the rewrite.

I'll also start looking at specific performance improvements now that the rewrite is done

cattywampus04 commented 1 year ago

I'll give it a look right now and report back!

[Edit: Providing I can figure out what to download lol. I thought it would just be a single file but all I see are source code zips? I'll keep looking while you reply and hopefully find it but if not, could you point me in the direction of what i need to grab? Thanks!]

[Edit 2: Yeah sorry I'm not sure what I am meant to download? All I see are source code downloads. Does this mean I would need to compile it myself? I have virtually zero knowledge on this kind of thing. The most development type stuff I've done is write Autohotkey scripts and Filemaker databases πŸ˜‚]

Oh my god I am so dense.

I get it now. The module is built into the latest beta of Companion entirely - which I can download from the Bitfocus website πŸ˜‚πŸ˜‚ Wow I am stupid sometimes.

cattywampus04 commented 1 year ago

Hello Ok I installed the latest beta - using OBS 28.1.2 - and the results were actually worse than with 2.4.2.

I think there's a memory leak or something? See the screenshot of task manager where the Node.js processes just run away - it got higher than that but I killed it as it was starting to make the system hang.

companion beta memory run away

bryce-seifert commented 1 year ago

Got it. Thanks for trying it, I’ll work on specifically targeting this issue next.

cattywampus04 commented 1 year ago

Hello, hope all is well.

Just wondering whether there has been any changes to the Companion 3.0 beta that would be addressing this issue? I last tried beta 5670, so there is a more recent beta available.

Again, I hope this doesn't come across as me trying to rush or pester. Am not in any rush at all.

Thanks!

bryce-seifert commented 1 year ago

I haven't made any changes to the module that I think would improve this.

However, there have been some changes to Companion itself that might be worth a try in terms how of it handles loading the modules.

I would try version 5790 to see if there's any improvement. Sorry I haven't had more time to work on this.

mat92140 commented 10 months ago

Hello @bryce-seifert,

I'm having the same issue as Catty with an OBS with around 100 sources and around 150 scenes. The CPU and RAM gets in heavy Work while I launch OBS, Companion is also unsuable for about 2 minutes. image

I'm using Companion 3.2.0 (3.2.0+6663-stable-b83f412f) and OBS Websocket 5.0.

Did you understand what is causing this issue ? Is there a Way to solve this ? Thanks,

bryce-seifert commented 9 months ago

@mat92140 @cattywampus04 If you want to download and try the latest Companion beta build, I hope to have addressed this issue. Let me know if it persists or any other issues pop up

cattywampus04 commented 9 months ago

Hi Bryce,

Thank you for getting around this issue.

I tried the beta (3.3.0+6783-a28706b9) along with OBS 30.0.2. At first I thought it was the same problem, I now am not sure what is happening - I think there is a secondary problem. Let me explain.

When I tried the above setup using my existing OBS scenes, while I did not have the memory usage runaway problem - the websockets server would throw an error that it disconnected after ~30 seconds. So, the beta build has absolutely changed something. The connection for connecting to OBS websockets in the Companion GUI just repeatedly spams the message in the screenshot, "Failed to load connection info: "TimeoutError: Timed out after 5s" - the spamming of it is less than 5s each time it spams it however. In the OBS websocket dialog, nothing appears - it doesn't appear it's constantly trying to reconnect, as far as OBS is concerned.

I tried a creating a blank scene collection. Companion connects to OBS and stays connected.

I thought, just to be thorough, I will go through and start deleting things from my main scene collection to see whether is has any effect on anything. As I started deleting scenes and the sources along with them, I noticed the time it took for the "websockets disconnection" notification popup to decrease. It certainly appeared to me that when enabling the OBS connection in the Companion GUI, Companion was parsing/curating (whatever technical term you would use πŸ˜‚) all of the scenes and sources ready to be used - and the fewer there were, the less time it took.

I also wondered whether there was some buggy source in my scenes that was causing Companion to bug out. Bear in mind, I have been using 2.3.1 and the latest OBS v27 for ages now without issue.

So, I slowly deleted scene by scene and tried connecting to websockets again. I got down to my final scene - and at this point I started deleting 1 source in that scene at a time. Every time, Companion would try to connect, it would show in the OBS websockets dialog as a connected session - then disappear, and then the Windows notification that the websocket client disconnected would appear - and the 5s timeout error in the Companion GUI would start spamming. I got down to the last couple of sources in the scene - a single folder (or Group as OBS calls them) and inside it was a single image source and it still caused an issue.

I tried rename the scene, the group name and the image source name, same problem...but, when I moved the image source out of the folder - Companion suddenly worked fine.

After a lot of trial and error, it appears to me that OBS groups/folders are causing the problem. I tried again creating a fresh scene collection - I added a single image source - Companion connected fine. I then nested that in a group/folder in OBS, and Companion would no longer work.

I have tried resetting my Companion settings to default. It's a fresh copy of OBS, and as I said, I had been using older OBS and Companion versions with folders/groups for ages (I use groups a lot). It appears to me that in the new versions of Companion, if you have groups/folders in your OBS - it breaks Companion.

Has anyone else reported this? It feels like such a fundamental feature of OBS scenes, I'm surprised it's not been picked up on before?

I have included a json with that scene and them 2 sources so you can see what I mean and see whether you can replicate the issue

It's impossible for me to test whether the original problem has been resolved in the beta if I am unable to load my scene collection as, as I said, I use groups/folders throughout.

Thanks

obs weird scene behaviour.json

2024-02-21 012959  2NDPC chrome Bitfocus_Companion_-_Admin_-_Google_Chrome

bryce-seifert commented 9 months ago

@cattywampus04 Thank you for the thorough explanation and json. I will take a look at this and get back to you soon. (I promise much sooner than this originally took hah!)

cattywampus04 commented 9 months ago

No rush on my part! Good things come to those who wait. Am happy to help where I can too!

mat92140 commented 9 months ago

Hi Everyone,

I ran into the same issue than Catty with the "Failed to load" I launch Companion then OBS. I can see in the Websocket Windows that messages are exchanged. At around 7400 messages sent the connection is lost and Companion is on fail of connection.

Here is the logs that I extracted in companion : module-log-21_02_2024-10_07_30.csv

With Catty's JSON : I didn't have any issue with using companion with or without any folders. But I enventually lost connection after quite a long time, here are the logs : module-log-21_02_2024-17_08_26.csv

Hope this will help you solve this ! Feel free to ask if you need other help !

bryce-seifert commented 9 months ago

Thanks for the logs. I found a couple of issues from the logs, I'm not sure they're related, but I've fixed them.

If you can give the latest Companion beta a try, it has the fixes. Again, not sure this will prevent the overall issue but should at least rule it out.

I was not able to recreate the issue using the JSON. I did get some notices about missing Lua scripts, so that's another variable I haven't been able to look into.

@mat92140 Do you have a scene collection JSON that fails that you would be able to share? Just trying to recreate the issue on my end to avoid having to parse logs back and forth

cattywampus04 commented 9 months ago

@bryce-seifert

Thank you for the latest beta. Your changes appear to have resolve the issue I was having with folders/groups in OBS scenes (I'm not like a super technical coding nerd - but if it can be explained to a lay person in a simplistic way that doesn't take too much of your time to explain, I'd be interested it knowing what changes you made? Just out of morbid curiosity!)

I am also happy to report that it appears that Companion is now connecting and is able to control sources. I obviously need to run more prolonged tests but it looks very promising. It takes around 30-40 seconds for Companion to do it's thing on my master scene collection - it's unresponsive during that time but comes back alive once done - completely serviceable!

I have been fighting with moving all my plugins and stuff over from OBS v27 to v30 - so I have been trouble shooting other stuff which has slowed me down (i've not actually used OBS or Companion for some time).

Couple of things I have noticed:

Thank you again - will report back with any more findings!

bryce-seifert commented 9 months ago

I'd be interested it knowing what changes you made?

The overall changes are that instead of sending multiple individual commands per source, commands are now sent in batches to reduce load. Additionally, with the most recent beta, I fixed some minor coding typos that could have thrown errors specifically with inputs.

Companion does not seem to reconnect to OBS if OBS is closed and reopened

I've seen another report of this, but have struggled to recreate it. In my testing, most cases of OBS reconnecting are recognized. But I'm not sure if it's a version issues or something else.

Is there a new version of the Stream Deck Companion plugin

I've personally never used the Elgato plugin, but I might recommend submitting an issue request on the main Companion repo for that.

cattywampus04 commented 9 months ago

Hey @bryce-seifert that's great. I've been tinkering tonight and it seems to be rock solid once it's connected.

Re: the not-reconnecting after closing OBS: when OBS loads, there is the "websockets connected" notification that pops up - but it doesn't actually do the loading of scenes/sources.

Let me know if there is anything you think I can provide to help with this.

Thank you once again!

bryce-seifert commented 9 months ago
  • but it doesn't actually do the loading of scenes/sources.

What specifically do you mean by scenes/sources not loading? Is this something in the Companion actions or variables that's not populating? Anything in the Companion logs? Does it report "Connected to OBS"?

In my testing, when reconnecting it updates sources, and recognizing all the changes I've tested. If you're able to provide a screen capture of the behavior that might help me understand it.

cattywampus04 commented 9 months ago

Hi @bryce-seifert - I apologise if I being confusing. I'll try explain again and report how I seem to be able to easily recreate the issue:

Companion Connections Edit

OBS Websockets

I can load OBS and Companion in either order the for the first time, and Companion will see OBS has loaded and connect to the Websocket server. The "messages in/out" will tick up as Companion looks through the scene collection and does it's thing ready to be used. Everything works as expected.

If I then close OBS, a Windows notification briefly pops up saying the websocket server has disconnected, and the Connections section shows that it has lost connection to the OBS websocket.

I then open OBS again, I get the "websocket connection" Windows notification, and Companion is able to control OBS immediately. There is not the 30second wait while Companion does it's thing scanning through scenes/sources like it does on first load - I assume it's storing the session in RAM or something so it doesn't have to do it's thing every time. The "messages in/out" do not tick up fast like they do on a first boot. Everything is working as it should.

If I then close OBS again, Companion does not seem to recognise that the websocket server is not loaded any more. The Connections section of Companion has a green tick in the Status column for the OBS connection. The Companion log does not have the expected "lost connection to OBS" line. Companion appears to still thing OBS is loaded.

If I then open OBS again, there is no Windows notification saying the websocket server has been connected to, and in the Websocket UI, there is no entry for Companion, no messages in/out etc. None of the buttons work. Companion continues to show it as connected. There are no further messages in the logs.

I can repeat closing/opening OBS over and over and nothing changes. The only way to get Companion to reconnect to the OBS websocket server is to disable the connection and re-enable it.

I hope this helps.

Thank you again for what you do.

bryce-seifert commented 9 months ago

Interesting, I'm having a hard time recreating this. I am on macOS, not sure if that is a factor.

Also, what version of OBS are you using? I'm testing on v30. If you're not using v30, could you verify this is still an issue with that version if possible?

cattywampus04 commented 9 months ago

I am using the latest version of OBS, 30.0.2.

I have just tried the same OBS and Companion beta on a second computer with a completely different setup and scene collection - and it does exactly the same thing on there. I grabbed the most up to date Companion beta and tried as well, same result.

Both computers are running Windows 11 23H2.

Let me know if there is anything else I can do to help.

bryce-seifert commented 9 months ago

Ok I was able to test this on Windows, and was finally able to recreate. It seems like in certain cases on windows, obs-websocket doesn't emit the "Exit" message the module was expecting. Luckily, I think the fix was pretty easy and the module now listens for an additional error that seems to be more reliable.

This should be in beta by tomorrow for testing!

bryce-seifert commented 9 months ago

@cattywampus04 Ok it’s available to download in the very latest beta now

cattywampus04 commented 9 months ago

Hello @bryce-seifert

Have tried the new beta - Companion reliably disconnects from the websocket and reconnects when loading OBS again now...

However a new issue appears to have risen:

Opening OBS for the first time after rebooting or toggling the OBS connection in the Companion connections UI, everything works fine. However closing OBS and reopening, it appears as if the ability to toggle source visibility stops working.

I can continue to create and use buttons that do things like start/stop recordings, change scene, open the filters dialog for a specific source. I can close and reopen OBS endlessly and it still results in the same problem. Only way to get things working again is to toggle the OBS connection in the Companion connections UI.

I have replicated this one two computers like I did previously.

There are no entries in logs.

Let me know what you need from me :)

Thanks!

bryce-seifert commented 9 months ago

Interesting, I'm not able to recreate this on my end on Mac or Windows. There's a brief period as it reconnects where it doesn't work, but once fully connected after a few seconds it works fine for me.

And just to make sure, there are no errors in the module logs accessed by the >_ Icon next the module?

cattywampus04 commented 9 months ago

Hi Bryce,

Since you were unable to recreate the issue, I've done more testing. I took everything back to a blank slate and tried and the problem seemed to go away for me. I think the problem is a plugin, StreamFX, which itself is in a perpetual beta.

When I have StreamFX installed, Companion becomes spotty with how it controls sources. Sometimes Companion will stop working altogether, other times it won't control things like source visibility or source filter visibility -- while continuing to control things like a media source volume or recording. It's very much an issue with something stopping interactions with sources (to my lay-persons brain anyway haha)

Would you be interested in me sending you a zip with:

  1. A portable OBS with StreamFX installed inside
  2. A test Companion config I have been testing with
  3. A test OBS scene collection I have been testing with
  4. A copy of the latest StreamFX installation file itself

I can provide more detailed guidance on how I cause it to stop working - you might be able to see something?

I'm not sure where the the issue lies -- with Companion or with StreamFX. I've used StreamFX for years along side Companion 2.3.1 and it always worked fine.

PS. I would need a place to send it that's not public as the StreamFX software is a Patreon only download, so I wouldn't want to put that up anywhere public.

Let me know.

PS there are these entries in the logs when it does stop working:

  1. When trying to toggle a source filter: debug,Request SetSourceFilterEnabled failed (Error: Your request is missing thefilterEnabledfield.)

  2. When trying to use a "Set source transform" debug,Request GetSceneItemId failed (Error: Your request is missing thesceneNamefield.)

There are never any entries for anything else.

bryce-seifert commented 9 months ago

Sure thing, I'm happy to try. You can upload it here

cattywampus04 commented 9 months ago

PS. I would need a place to send it that's not public as the StreamFX software is a Patreon only download, so I wouldn't want to put that up anywhere public.

Do you have somewhere I can send you the zip that is not public? I can DM or email you a Dropbox link or something if that works for you.

Thanks!

PS I also noticed that session duration disappearing after 1 minute thing - but because the actual session remained and the messages in/out kept ticking up, and everything seemed to continue working, I never thought much of it.

bryce-seifert commented 9 months ago

Sorry! I pasted the wrong link. This is the upload link

cattywampus04 commented 9 months ago

Awesome! Uploaded that file now. There's a read me text file with inside. I hope it's of some use!

Let me know whatever I can do to help, and once again, thank you!

Itaku commented 8 months ago

Hey all,

I use OBS and Companion for a touring live entertainment show and run into this same problem very frequently on MacOS, most often after OBS is restarted and the Companion connection config goes into the timeout loop as shown above.

I don't have access to my log files right now as my gear is currently in a trailer, but next weekend I'll be trying the beta build and let you know how it goes and share log files here if needed.

bryce-seifert commented 8 months ago

@Itaku Did you get a chance to try the beta build, and if so are you still experience the issue?

Itaku commented 8 months ago

@Itaku Did you get a chance to try the beta build, and if so are you still experience the issue?

Just got home from a show last weekend, 3.3.0+6841 worked great. Took seconds rather than minutes for Companion to connect to OBS. Only at one point had to restart Companion to get it to work and after that worked flawlessly.

This is on a MacBook Pro 16" M3 Max.

bryce-seifert commented 8 months ago

Glad to hear it's improved.

Only at one point had to restart Companion to get it to work

Interesting, do you know what was going on at that point? And did the module crash / any errors, or was it just stuck?

Itaku commented 8 months ago

@bryce-seifert Not sure what happened before that caused it to hang, but it just became stuck and nothing was syncing basically. It's still a major improvement over every single time we made a new scene or source in OBS which is our problem currently in stable build.

We're off this weekend but next weekend I'll be sure to make sure to let my guys know to note what happens before having to restart companion.

cattywampus04 commented 8 months ago

Hi @bryce-seifert

Just a quickie to ask whether you got my the zip file that I sent to your Dropbox? Not pestering you or anything, am not in a rush for anything at all - just wanted to check you got it!

Thanks!

bryce-seifert commented 8 months ago

@cattywampus04 Thanks for checking, I got the file but haven't had time to fully investigate unfortunately. I will try and get on it soon, sorry for the delay

Yinxo commented 8 months ago

I'm glad i found an active thread with my trouble.

before, i'm on OBS version 30.1.1 and Companion 3.2.2 (3.2.2+6688-stable-7417d2a0).

Now... my problem is, even after first start, the connection seems to be not there. in Companion it say its there but in the OBS web-socket settings there is no running connection.

image image

OBS - Sources so not loading:

image

My solution for now is that i made a reconnect button for OBS in companion. and thats working for now.

i just wanted to ask, are you still working on a solution or is there one that i can update to another version?

thanks in advance :)

Yinxo commented 8 months ago

here an addition on the log - tested with beta 3.3.0+6881

Same problem but is shows in another way. After manual reconnect, it works again

Studio-PC-01_companion_log_20240403-0931.csv

bryce-seifert commented 8 months ago

@Yinxo In your particular instance, it is returning "ECONNREFUSED" which likely points to a networking or connection issue. Does it fail to connect every time you launch companion? What is your setup like: is Companion on the same computer as Companion, or across a network?

Yinxo commented 8 months ago

Well OBS and Companion are running on the same machine but it started to happen around 3 weeks ago. before, everything was fine. Companion and every device is running on a closed network here

and yeah it happens to be every time i start up companion and obs.. :(

Yinxo commented 8 months ago

this is how it looks like when i freshly start the machine in the morning: just reconnecting in companion is all i`ve to do to make it work but it is annoing <.<

Bild (1)

Studio-PC-01_companion_log_20240405-0834.csv

bryce-seifert commented 7 months ago

@Yinxo Unfortunately the general log does not provide any detailed info to tell what's happening here.

Can you see if there are any additional messages by opening the module log (located at the >_ icon) before you start the module?

Screenshot 2024-04-05 at 4 21 32β€―PM
Joelsuperstar commented 6 months ago

I have the same problem as @Yinxo above:

Versions: OBS: 30.1.2 Companion: latest 3.3.0 stable build. Both on the same desktop.

I start the computer; OBS and companion automatically get started. Together with some other programs.. Quick note that i added that -disable-shutdown-check in OBS startup. Not sure if that matters. But that it always starts in normal mode, without asking to start in safe mode and or normal mode.

I have set a trigger with a condition that OBS should be connected to change some things in OBS. For example hide all the things in a certain collection and set the projector output. But most of the times companion is saying that it is connected to OBS.. But it is not connected. It is even possible to fully close OBS.. Like pressing the x in the corner. Haven't checked yet if something is still running in task manager but this is weird.

My "ducttape fix" is that I start a trigger when companion starts, that closes the OBS connection in companion, and start the connection again. This works but is it is an unwanted fix.

I don't see the red "timeout" box that got sent in this thread around Februari. I think that one is fixed, but I saw that previously (in an earlier version of Companion). I also see nothing in the module log because it all happens when I start companion... I can close and start the connection manually, which will show some lines in the log, but it all happens at the start of companion. Is there an option to see that log?

Can it be that OBS starts the websocket when giving that popup to start OBS in safe mode or normal mode, but that it likes make a new websocket connection and keeping the old one active in the background? Like i dont get a popup because of that -disable-shutdown-check addition.

It is really hard to replicate. I tried to replicate it on my personal computer, but that one works most of the times.. So it is really weird.