Skip to contentSkip to conversation

Bitbake server startup issues - need a radical rethink?

DISCUSSION Richard Purdie 2 participants 2 messages Aug 23, 2020

lore
Share & tools
lore
#0 lore raw

The bitbake server startup code is proving problematic. It nearly works but there are a few issues.

Basically it comes down to us trying to daemonise one python process from inside another one so they run independently. The python interpreter simply isn't up to it.

Our current approach uses os.fork() twice. We have to use os._exit() on the end codepaths rather than sys.exit() as that would raise SystemExit inside the original codebase inside a second process, meaning execution happens there twice which is really really bad.

If we use os._exit(), atexit and multiprocessing.Finalize() constructs don't work. This can leads to unexpected problems as we're effectively breaking an significant part of the python's behind the scenes machinery.

We could go back to the setup where we os.fork() twice then launch a multiprocessing.Process() but it feels like we're relying on a hack.

I'm also noting logging is working differently in tinfoil and knotty. I think this is due to the state of python's logging in the parent environment, pre-fork. I really don't like the fact we have an inconsistent base environment for the server.

This is a long way of saying, I think we need to radically change the way bitbake's server process is started by making it a new process execution. That will break the mechanism we determine when the UI is "ready" and give us a whole new world of races to potentially worry about but I think its the only way we're going to get out of this current 'mess'.

I'm particularly worried about what this means for the LTS release though as I'd effectively be writing these race issues off as unfixable there unless we take the new process setup code which would seem a little unwise.

Cheers,

Richard

#1 lore raw
Quoted 33 lines · Richard Purdie

The bitbake server startup code is proving problematic. It nearly works but there are a few issues.

Basically it comes down to us trying to daemonise one python process from inside another one so they run independently. The python interpreter simply isn't up to it.

Our current approach uses os.fork() twice. We have to use os._exit() on the end codepaths rather than sys.exit() as that would raise SystemExit inside the original codebase inside a second process, meaning execution happens there twice which is really really bad.

If we use os._exit(), atexit and multiprocessing.Finalize() constructs don't work. This can leads to unexpected problems as we're effectively breaking an significant part of the python's behind the scenes machinery.

We could go back to the setup where we os.fork() twice then launch a multiprocessing.Process() but it feels like we're relying on a hack.

I'm also noting logging is working differently in tinfoil and knotty. I think this is due to the state of python's logging in the parent environment, pre-fork. I really don't like the fact we have an inconsistent base environment for the server.

This is a long way of saying, I think we need to radically change the way bitbake's server process is started by making it a new process execution. That will break the mechanism we determine when the UI is "ready" and give us a whole new world of races to potentially worry about but I think its the only way we're going to get out of this current 'mess'.

Quoted 4 lines

I'm particularly worried about what this means for the LTS release though as I'd effectively be writing these race issues off as unfixable there unless we take the new process setup code which would seem a little unwise.

As a normal dunfell user, bitbake startup issues aren't something I've ever encountered. So for most normal users not having these race issues fixed in dunfell probably isn't a concern.

As dunfell maintainer, the intermittent bitbake server startup issues on the autobuilder are an annoyance, but not the end of the world. I've been living with it and don't see any reason why I can't continue to.

Maybe after the new process setup code has "baked" for a few months we can revisit this.

Steve

Quoted 1 line