Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support reset photon at fork #282

Merged
merged 1 commit into from
Dec 6, 2023
Merged

Conversation

yuchen0cc
Copy link
Contributor

In photon context, event engine based module need reset after fork, if exec will not be called after fork.
This is implicitly done by pthread_atfork hook.

@CLAassistant
Copy link

CLAassistant commented Nov 29, 2023

CLA assistant check
All committers have signed the CLA.


namespace photon {

static ResetHandle *&ree_list() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems no need to hide the list inside a function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

outter function has been removed.

namespace photon {

static ResetHandle *&ree_list() {
static thread_local ResetHandle *list = nullptr;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better use intrusive_list<ResetHandle> list;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using pointer is meant to avoid construct/destruct.

}

void reset_all_handle() {
if (ree_list() == nullptr)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will be no need to handle nullptr, when using intrusive_list<ResetHandle>

thread_yield(); // give a chance let eloop to execute do_wait
pthread_atfork(nullptr, nullptr, &fork_hook_child);
if (reset_handler == nullptr) {
reset_handler = new SignalResetHandle();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better hide a handler object inside a function, rather than new one

@@ -240,6 +254,10 @@ int libcurl_init(long flags, long pipelining, long maxconn) {

libcurl_set_pipelining(pipelining);
libcurl_set_maxconnects(maxconn);
if (reset_handler == nullptr) {
reset_handler = new CurlResetHandle();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better hide the handlers inside a function

return 0;
}
};
static thread_local CurlResetHandle *reset_handler = nullptr;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better hide the handlers inside a function like this:

static CurlResetHandle* get_reset_handler() {
    static thread_local unique_ptr<CurlResetHandle> handler { new CurlResetHandle};
    return handler.get();
}

And there's no need to destruct it explicitly.

The same for aio, etc.

In photon context, event engine based module need reset after
fork, if exec will not be called after fork.
This is implicitly done by pthread_atfork hook.

Signed-off-by: yuchen.cc <yuchen.cc@alibaba-inc.com>
@lihuiba lihuiba merged commit 8f8e96c into alibaba:release/0.7 Dec 6, 2023
7 checks passed
lihuiba pushed a commit that referenced this pull request Dec 6, 2023
* Mute an UBSan check error for SCOPED_LOCK macro (#283)

* io: support reset photon at fork (#282)

In photon context, event engine based module need reset after
fork, if exec will not be called after fork.
This is implicitly done by pthread_atfork hook.

Signed-off-by: yuchen.cc <yuchen.cc@alibaba-inc.com>

---------

Signed-off-by: yuchen.cc <yuchen.cc@alibaba-inc.com>
Co-authored-by: Bob Chen <beef9999@qq.com>
Co-authored-by: yuchen0cc <91253032+yuchen0cc@users.noreply.github.com>
lihuiba pushed a commit that referenced this pull request Dec 12, 2023
* Mute an UBSan check error for SCOPED_LOCK macro (#283)

* io: support reset photon at fork (#282)

In photon context, event engine based module need reset after
fork, if exec will not be called after fork.
This is implicitly done by pthread_atfork hook.

Signed-off-by: yuchen.cc <yuchen.cc@alibaba-inc.com>

* RPC support graceful shutdown

---------

Signed-off-by: yuchen.cc <yuchen.cc@alibaba-inc.com>
Co-authored-by: Bob Chen <beef9999@qq.com>
Co-authored-by: yuchen0cc <91253032+yuchen0cc@users.noreply.github.com>
lihuiba added a commit that referenced this pull request Dec 16, 2023
* Mute an UBSan check error for SCOPED_LOCK macro (#283)

* io: support reset photon at fork (#282)

In photon context, event engine based module need reset after
fork, if exec will not be called after fork.
This is implicitly done by pthread_atfork hook.

Signed-off-by: yuchen.cc <yuchen.cc@alibaba-inc.com>

* RPC support graceful shutdown

* fs: support xattr for extfs and subfs (#298)

Signed-off-by: yuchen.cc <yuchen.cc@alibaba-inc.com>

* Sequential mutex (#294)

seq_mutex

* exit(0) requires stdlib.h (#303)

* fix e2fs include dir name (#301)

Signed-off-by: yuchen.cc <yuchen.cc@alibaba-inc.com>

* [feat] http client with cert

Signed-off-by: zhuangbowei.zbw <zhuangbowei.zbw@alibaba-inc.com>

---------

Signed-off-by: yuchen.cc <yuchen.cc@alibaba-inc.com>
Signed-off-by: zhuangbowei.zbw <zhuangbowei.zbw@alibaba-inc.com>
Co-authored-by: Bob Chen <beef9999@qq.com>
Co-authored-by: yuchen0cc <91253032+yuchen0cc@users.noreply.github.com>
Co-authored-by: Huiba Li <lihuiba@gmail.com>
Co-authored-by: zhuangbowei.zbw <zhuangbowei.zbw@alibaba-inc.com>
Co-authored-by: Lanzheng Liu <lanzheng.liulz@alibaba-inc.com>
lihuiba added a commit that referenced this pull request Dec 18, 2023
* Mute an UBSan check error for SCOPED_LOCK macro (#283)

* io: support reset photon at fork (#282)

In photon context, event engine based module need reset after
fork, if exec will not be called after fork.
This is implicitly done by pthread_atfork hook.

Signed-off-by: yuchen.cc <yuchen.cc@alibaba-inc.com>

* RPC support graceful shutdown

* fs: support xattr for extfs and subfs (#298)

Signed-off-by: yuchen.cc <yuchen.cc@alibaba-inc.com>

* Sequential mutex (#294)

seq_mutex

* exit(0) requires stdlib.h (#303)

* fix e2fs include dir name (#301)

Signed-off-by: yuchen.cc <yuchen.cc@alibaba-inc.com>

* [feat] http client with cert

Signed-off-by: zhuangbowei.zbw <zhuangbowei.zbw@alibaba-inc.com>

* minor fix for std-compat (#307)

* minor fix for std-compat

* rpc::string add empty method

* set io_uring eventfd non-blocking

---------

Signed-off-by: yuchen.cc <yuchen.cc@alibaba-inc.com>
Signed-off-by: zhuangbowei.zbw <zhuangbowei.zbw@alibaba-inc.com>
Co-authored-by: Bob Chen <beef9999@qq.com>
Co-authored-by: yuchen0cc <91253032+yuchen0cc@users.noreply.github.com>
Co-authored-by: Huiba Li <lihuiba@gmail.com>
Co-authored-by: zhuangbowei.zbw <zhuangbowei.zbw@alibaba-inc.com>
Co-authored-by: Lanzheng Liu <lanzheng.liulz@alibaba-inc.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants