Git Product home page Git Product logo

Comments (18)

guidosarducci avatar guidosarducci commented on September 26, 2024 1

... pushing your code to your branch even if not doing a PR yet?

Could you explain this part of your question? It's not clear what you're asking. Do you prefer I just PR the changes and move discussion there?

Can you explain how you're solving this ...

Sure. First some background information:
PEP 0446
Python Doc: Subprocess Management
W32 CreateProcess function
W32 SetHandleInformation function

All changes are localzed to the resources/site-packages/quasar/daemon.py file, which manages spawning the child process for the quasar binary. The changes are clear and isolated, so please review those first.

Next, let me expand on how the quasar binary is inheriting open files, with a few key points:

  • Kodi's version of Python has new file descriptors created to be inheritable
  • by default child processes from a call to subprocess.popen() will inherit permitted files
  • the quasar binary child process has its stdout redirected via a pipe (important for later)

The other important thing to note is from the Python docs on subprocess.popen() call paramters:

If close_fds is true, all file descriptors except 0, 1 and 2 will be closed before the child process is executed. (Unix only). Or, on Windows, if close_fds is true then no handles will be inherited by the child process. Note that on Windows, you cannot set close_fds to true and also redirect the standard handles by setting stdin, stdout or stderr.

And here is where the solution gets more complicated. On Unix (Linux/Android/etc) I just add the parameter close_fds = True to the subprocess.popen() call. But this won't work on Windows because the plugin needs to use a pipe to read the quasar binary stdout. To work around this limitation on Windows, I instead call a new clear_fd_inherit_flags() function before the normal subprocess.popen() call. This function iterates over open regular files/directories and marks them as non-inheritable, so that the quasar child process will not hold them open and interfere with addon updates.

Now, I've reproduced the problem/solution in Python on an old Windows box, but I don't run Kodi there, which is why I asked someone to help test it on Windows.

Anyone?

from plugin.video.quasar.

scakemyer avatar scakemyer commented on September 26, 2024

Just ran into this while upgrading Kodi. It's quite a nasty bug.

from plugin.video.quasar.

tomer953 avatar tomer953 commented on September 26, 2024

Also, I forgot to mention, that from My experience, it's not happening when the skin is hosted by the official repository, only from private repo's.

from plugin.video.quasar.

tomer953 avatar tomer953 commented on September 26, 2024

@scakemyer , sorry for bumping it...
but other skinners are keep asking me if this already has been reported\solved..
so I wonder if you have spare time to look into it.

many thanks for your hard work.

from plugin.video.quasar.

scakemyer avatar scakemyer commented on September 26, 2024

I haven't forgotten about this, I just currently don't have any clue what is causing this. Could you provide a more detailed debug log? (please no pastebin or forum link, really tired of having to solve CloudFlare captchas)

from plugin.video.quasar.

tomer953 avatar tomer953 commented on September 26, 2024

Actually, my skin is already in the official repository, which for some weired reason is not affected with this problem.
However, I have a small log from the days my skin was in private repo:
http://xbmclogs.com/pucp0vqvb

I had this issue every few days when I pushed new updates to my repo, I also searched for some more details in the log - but none. even in debug mode.
one day, while updating failed, and I had the "black screen" issue, I went to my skin dir, to see what is going on there - then I saw that almost all the file deleted (like they should, when updating), except for the "Textures.xbt" file in the "media" folder. when I tried to "shift+delete" it, with windows explorer, I recieved a msg that "pulsar.exe" is using this file, and it cannot be removed.
that's all the details I have..

If you have some clue about it, and you need some testing, I have friends with private skins which can help us.

from plugin.video.quasar.

ShlomiD83 avatar ShlomiD83 commented on September 26, 2024

sorry for bumping this, but i have the same problem with Xonfluence skin..

from plugin.video.quasar.

guidosarducci avatar guidosarducci commented on September 26, 2024

This bug is definitely nasty, and aggravated me to point I just had to kill it. The core issue is that the quasar binary inherits all of Kodi's open files, including things like skin fonts and graphics, which means they can't be deleted and replaced as part of an update. An even bigger PITA is that no one solution will work on both Android (my platform) and Windows (not my platform), but I think I have an approach for each.

Before I PR this, I'd appreciate if some other guinea pigs users could try out the updated quasar plugin I attached, especially on Windows, and provide feedback.

You can confirm the issue with inheritied files yourself using 'lsof' on Unix (Linux/Android/etc) or 'handle.exe' on Windows (Handle v4.0). Try doing this with your old quasar installation and then my updated one to see the difference.

plugin.video.quasar-fix-close-quasar-fds.zip

from plugin.video.quasar.

scakemyer avatar scakemyer commented on September 26, 2024

Can you explain how you're solving this and pushing your code to your branch even if not doing a PR yet?

from plugin.video.quasar.

ShlomiD83 avatar ShlomiD83 commented on September 26, 2024

your fix isn't working on windows.
i just need to copy the files from your zip and try to update the skin?

from plugin.video.quasar.

teamThevibe avatar teamThevibe commented on September 26, 2024

anyone test the fix ?
i want to update my skin ... :)

from plugin.video.quasar.

ShlomiD83 avatar ShlomiD83 commented on September 26, 2024

1 comment above you, not working on windows.

from plugin.video.quasar.

metate avatar metate commented on September 26, 2024

@guidosarducci It won't work on windows because file handles are not the same as posix fds. The handle for textures.xbt can be above 1000. See:

 ------------------------------------------------------------------------------
quasar.exe pid: 14316 DESKTOP-PJ5OMUK\metate
   10: File  (---)   C:\Users\metate\AppData\Roaming\Kodi\userdata\addon_data\plugin.video.quasar\bin\windows_x64
  1F4: File  (---)   C:\Windows\System32\en-US\mswsock.dll.mui
  6F0: File  (---)   C:\Users\metate\AppData\Roaming\Kodi\addons\skin.phenomenal\media\Textures.xbt
------------------------------------------------------------------------------

I would suggest setting close_fds=True on all platforms (confirmed working). This will require removing stdout and stderr redirects on windows so IMHO the best way to handle it is to replace the logging code to use the quasar RPC mechanism instead (preferably using batch logging to avoid overhead).

Edit: the code already supports RPC for logging. We don't really need to redirect stdout/stderr. The fix should be fairly easy.

Nice catch @guidosarducci

from plugin.video.quasar.

tomer953 avatar tomer953 commented on September 26, 2024

Sorry for being away, thank you all, great work.

@scakemyer ... thoughts?

from plugin.video.quasar.

guidosarducci avatar guidosarducci commented on September 26, 2024

Was away for a little bit so catching up...

@metate Thanks for trying my suggestion of using handle.exe. When I hadn't seen a response from anyone I broke down and built a Kodi Windows VM, and you confirmed what I first saw as well.

@scakemyer The root problem is a messy one, and a Kodi bug AFAIC. Kodi leaks some files to child processes, and prevents others from being inherited. Worse, the files that are leaked depend on the platform and runtime used. This stuff should properly be fixed in Kodi itself.

That said, I've updated my Windows workaround to use the pure MS CRT, and confirmed it works on Kodi Windows. I'll do a PR shortly, and folks can try it from there.

from plugin.video.quasar.

ShlomiD83 avatar ShlomiD83 commented on September 26, 2024

confirmed working on windows, thnx @guidosarducci .

from plugin.video.quasar.

scakemyer avatar scakemyer commented on September 26, 2024

Awesome work here @guidosarducci, sorry I was also away the past few weeks.

from plugin.video.quasar.

scakemyer avatar scakemyer commented on September 26, 2024

Should be fixed by #469 thanks to @guidosarducci

from plugin.video.quasar.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.