unoconv / unoserver

MIT License
496 stars 69 forks source link

Multiple processes use 100% CPU #19

Closed Rafiot closed 2 years ago

Rafiot commented 2 years ago

I'm using unoserver in pandora do convert office docs into PDFs and it all works very good, thank you for the tool! The issue I have it that after a while, I have a whole bunch of soffice.bin processes using 100% CPU, even is no conversion is happening (but I can still convert files as expected). And I need to kill them manually, simply stopping unoserver doesn't kill them.

Do you have any idea how I could debug that? I noticed it first on a machine where AppArmor is enabled, but it seems to also happen without the profile.

regebro commented 2 years ago

I improved the handling of signals, some signals might have resulted in Unoserver existing without Libreoffice exiting. I believe that now Unoserver should not quit and leave LibreOffice hanging, so that should at least solve THAT.

Why soffice is using 100% and doesn't exist, well, that's a different mystery. Can you try converting those specific files with just soffice?

Rafiot commented 2 years ago

Thank you for the update, I'll update the version and see what happen. And I'll give it a shot as you suggested to see what happen.

Are you aware of a way to unceremoniously kill the soffice process after a timeout? Especially for the headless runs, we really don't want it to run forever.

Rafiot commented 2 years ago

Okay, seems it's because killing unoserver (SIGTERM) doesn't kill soffice, and I have then multiple soffice processes trying to connect to the socket.

Is there a preferred way to gracefully stop unoserver so it properly kills the soffice process?

mmeisso commented 2 years ago

Hi,

It seems that unoserver is ignoring completely signals when hanging on https://github.com/unoconv/unoserver/blob/c76c598259521608b312b9c1117594f88ae7cbfa/src/unoserver/converter.py#L201

I could only kill it with a sigkill, which let intact soffice.bin processes. I'm running server and convert on different containers, so i can't kill by hand soffice.bin "incriminated" processes. If someone knows how to kill that...

regebro commented 2 years ago

I could probably make the converter easier to kill in that situation, but that wouldn't change anything, the server is still hanging. There's no way for the converter to kill the server if it's hanging. Your problem here isn't with the converter, but with the libreoffice process.

regebro commented 2 years ago

@Rafiot It's really hard to test how it behaves in different situations, but in the update what I did is that when unoserver gets a sigterm it just passes that on to soffice. It shouldn't exit unless soffice exits. If it does, just sigkill it instead, then it will send sigkill to soffice, and it will exit.

Rafiot commented 2 years ago

I just noted that the problem mostly occurs for me on an ubuntu 20.04 server, but not on my dev box running Ubuntu 21.10. Could it be that the version of libreoffice on ubuntu 20.04 is not handling the signal properly?

And I'm thinking of an other way to handle the case: right now, I'm just launching unoserver with Popen, but I should use the UnoServer class instead and launch it with start so I have the libreoffice process object that I can check and kill it if need to.

regebro commented 2 years ago

Yeah, if you are running it from inside python, and are using the system python, using the class could be a good way to do it.

Rafiot commented 2 years ago

It seems I solved it with a more recent libreoffice, and using the class directly.