facebook / facebook/folly

Inconsistent ordering in AtFork's prepare() rollback vs parent() execution

Open
#2,452 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
30.5k
Forks
5.9k
PR merge metrics
No merged PRs in 30d

Description

In the AtFork implementation, there appears to be an inconsistency in the ordering of handler execution between the rollback in `prepare()` and the execution in `parent()`.

When a prepare handler fails, the code needs to rollback previously successful prepare handlers. Currently, this is done in reverse order:

https://github.com/facebook/folly/blob/main/folly/system/AtFork.cpp#L40
```cpp
for (auto untask = tasks.rbegin(); untask != task; ++untask) {
if (auto& f = untask->parent) {
f();
}
}
```

However, in the `Parent()` function, handlers are executed in forward order:

https://github.com/facebook/folly/blob/main/folly/system/AtFork.cpp#L52
```cpp
for (auto& task : tasks) {
if (auto& f = task.parent) {
f();
}
}
```

Can anyone tell me the reason?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.