matrix-eno-bot icon indicating copy to clipboard operation
matrix-eno-bot copied to clipboard

Feature Request: allow async execution of subprocesses (bot commands)

Open h0p07 opened this issue 3 years ago • 3 comments

Lets create new command sleep.sh

#!/bin/bash
echo 'bot goes sleep'
sleep 60
echo 'bot has awoken'

2021-07-23 02:57:34,328 | bot_commands [DEBUG] OS command "sleep.sh" with args: "[]" and it stops receiving commands for 60 seconds, whole debug console stopped, all communication to server.

How to fix it?

Tested on Python 3.9.2/Python 3.7.3

h0p07 avatar Jul 23 '21 00:07 h0p07

Thanks :clap: @h0p07 for pointing that out.

Yes, this is how it is currently implemented.

... command is received ...
await self._os_cmd(...)

async def _os_cmd(...)
   subprocess.Popen(...)
   await send_text_to_room(..., response, ...)

Why was it implemented like this? For simplicity, and to avoid tricky situation. I am not sure what problems can (and will) arise if async behavior is permitted.

Does anyone have any thoughts on what could go wrong? Or if it is safe in the context of matrix-nio to all these user-defined commands to be async?

Comments? Feedback?

8go avatar Aug 05 '21 17:08 8go

I just executed update os command with eno-bot and was surprised that is actually run sudo apt-get update with no problems (though sudo could be a problem in itself...). But I couldn't examine the process' execution -- only the outcome. Async execution would be great!

unreal79 avatar Oct 09 '21 04:10 unreal79

Another problem arose from lack of async: message length limit. I've executed custom command that outputs more then 5000 lines of text. Judging by debug log, eno-bot sent the huge message back to my Element client, but Element didn't like it and the whole message was lost without a trace.

I don't know eno-bot internals, but forking process to execute command asynchronously could be pretty straightforward implementation IMHO.

unreal79 avatar Oct 09 '21 05:10 unreal79