Skip to contentSkip to conversation

Bitbake server startup issues - need a radical rethink?

bitbake-devel Richard Purdie 1 participant 1 message Aug 23, 2020 1 message not in the archive

lore
Share & tools
lore
#1 lore raw
In reply to a message not in the archive
Quoted 32 lines · Richard Purdie via lists.openembedded.org

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.

I tried some experiments locally and we can relatively easily drop an execlp() call into the server startup which would give us a fresh python interpreter. This is probably a good thing and means most of the rest of the startup code can be left alone from a race perspective as we can pass the fds over the exec call.

The downside is we can't stuff the "configuration" down the execlp() call. We have code to transfer the config from the UI to the server but it has known bugs (exposed by mem res bitbake) so if we move to use execlp(), the commandline will have glitches. We do need to fix these anyway. If we do fix those, memory resident bitbake will look in better shape.

Some observations:

a) We do a double parse of the configuration on startup as the initial config doesn't match the final config, even today. We really want to avoid that.

b) My execlp() experiment makes multiple parses even worse as the configurations fail to match even more

c) There is something wrong with tinfoil's debug output, its being duplicated onto the console at times.

d) There is something wrong with the server logging. When I removed the multiprocessing.Process(), the debug output in bitbake-cookerdaemon.log disappeared. Not entirely sure why, it wasn't intended and shouldn't have changed, not sure I dare look.

e) updateToServer() has a verbose parameter but the configuration doesn't. That is interesting and probably broken.

f) updateToServer() doesn't cover nosetscene, setsceneonly, skipsetscene, server_only, limited_deps, runall, runonly. There are open bugs in bugzilla re: memres this would explain.

g) writeeventlog is badly handled, set at server startup and ignored

I think what we need to do is figure out the minimal set of change needed to make this work, that would be the possible fix for dunfell, then we need to pull this apart and try and make it less crazy.

Cheers,

Richard