Repository navigation
forcibly close DB and cache socket connection post-fork - #8580
Conversation
| def __clean_on_fork__(self): | ||
| pid = os.getpid() | ||
| if pid not in self.__dict__['__forks__']: | ||
| self.__dict__['__forks__'][pid] = True |
There was a problem hiding this comment.
We have to access this via __dict__ instead of getattr to avoid a recursive loop (because __getattr__ calls this function via _get_local).
There was a problem hiding this comment.
I also tested this out by printing this dict in a tight loop of awx-python forks, and the data structure for each process never grows beyond two keys (the parent pid, and the current process pid).
So in effect, this branch is entered one time when a child process does getattr(settings, ...), and then after that, it's a no-op.
|
Build failed.
|
8ceb349 to
8317dd7
Compare
|
Build succeeded.
|
8317dd7 to
12a237f
Compare
we've seen evidence of a race condition on fork for awx.conf.Setting access; in the past, we've attempted to solve this by explicitly closing connections pre-fork, but we've seen evidence that this isn't always good enough this patch is an attempt to close connections post-fork so that sockets aren't inherited post fork, leading to bizarre race conditions in setting access
12a237f to
adfd8ed
Compare
|
Build succeeded.
|
matburt
left a comment
There was a problem hiding this comment.
This harkens back to when Ansible would change pids occasionally on us during event processing years ago.
|
Build succeeded (gate pipeline).
|
we've seen evidence of a race condition on fork for
awx.conf.model.Settingaccess; in the past, we've attempted to solve this by explicitly closing
connections pre-fork, but we've seen evidence that this isn't always
good enough
this patch is an attempt to close connections post-fork so that sockets
aren't inherited post fork, leading to bizarre race conditions in
setting access