unoconv / unoserver

MIT License
585 stars 81 forks source link

About cancelling client request #134

Open rastermechanism opened 1 month ago

rastermechanism commented 1 month ago

Hello, I have a query, is it possible to cancel the ongoing convert request on client side.

Here is the full scenario, I am using unosever client to send request for conversion to a remote server which is docker contaner. Further I am using fastapi to make this conversion to look like REST api. So basically from fastapi I am initiating convert request to remote container, However if conversion is taking too much time, like more than 10 secondfs, I want to timeout and return the response as timeout, which I have managed using asyncio, However real request was not cancel though response has been return from REST API. What actually I want to cancel the ongoing client request to remote unoserver, gracefully and cleanup any client side mess, before returning the response. how to do that? Any help would be much appreciated.

regebro commented 1 month ago

I don't think that's possible, I'm not aware of any mechanism to get LibreOffice to stop loading or exporting a document, which is what is happening in the background.

rastermechanism commented 1 month ago

@regebro thanks for the speedy reply, may be in future I will deep dive with LibreOffice, for now will use defer cleanup mechanism from Fastapi. Beside I have observed if bridge is down docker container still showing healthy and any incoming request just hangsup for infinite time. Try to add some health check mechanism which I have added using healthcheck.sh its just a small file script which checks if socket is still open at 2002 and if it fails more than 3 times restart the contaner. I think this feature will add little bit fault tolerance, though not supported natively in docker and we dont want to use swarn. But still a small utility will help a lot to the community.

Thanks

regebro commented 1 month ago

Yeah, I think in the case of stuck conversions, which sometimes happens, some way of killing LibreOffice and restarting it must happen.

regebro commented 1 month ago

Unfortunately, I can't find any way of doing this. I can add a timeout, and kill the Libreoffice process, but somehow the Libreoffice process does not stop until after it finishes the conversion.

regebro commented 1 month ago

So, I actually did find a solution today, and 3.0b1 is released with a --conversion-timeout argument to unoserver, that will cause unoserver to terminate Libreoffice and exit after a certain time. Please test!