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
Server termination issue #8
Comments
Ok, after thinking about it there is one further approach: |
Nice catch. Thanks.
I guard the signal handler with compare_exchange_strong in order for it to
be called only once.
So, #2 is not a problem.
However, #1 (violation of specification) is definitely a problem.
I'll also find the solution.
…On Sun, Apr 3, 2022 at 7:37 AM Andrea Cocito ***@***.***> wrote:
Ok, after thinking about it there is one further approach:
e) Have one thread take all the signals and sleep forever on a
sigwaitinfo(), then the same thread can do anything outside interrupt
context (or detach a temporary thread to do the job).
I will try to find half an hour to code this in the next days.
A.
—
Reply to this email directly, view it on GitHub
<#8 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AQGJVRD5JJGMPYI2OTUE2GLVDDD2XANCNFSM5SK6Q65A>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Now, I'm writing code to use a dedicated thread to handle signals, as suggested in the gRPC forum. |
Ok, I’ll wait so we don’t overlap.
I think that sigwaitinfo is much cleaner than installing signal handlers.
Cheers,
A.
…Sent from my iPhone
On 3 Apr 2022, at 12:25, Mikio Hirabayashi ***@***.***> wrote:
Now, I'm writing code to use a dedicated thread to handle signals, as suggested in the gRPC forum.
Please wait for it.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.
|
I submitted the change. Please check it on your environment. |
Thanks, |
Hi, |
Thanks for checking the change. One of the main objectives of Tkrzw over Kyoto Cabinet is to improve concurrency. As for a user account on FreeBSD, I don't need one currently. I'd like to ask it when other issues happen. |
I'm lost. Where is this code ? Can we see it ? |
The change is this: e9f1c44 |
Hello,
I noticed a little termination issue.
Currently the only way to terminate tkzrw_server is through a signal, however this is what happens if I start a plain server, do no other action, wait a couple of seconds and then hit control-C:
This happens:
Digging a bit into the code it seems that there are actually two separate issues:
void ShutdownServer(int signum)
is installed as signal handler, and it callsserver->Shutdown(deadline)
, this is explicitly forbidden by the grpc documentation and known to cause undefined behaviour (see the discussion on absl: Potential Mutex deadlock - when using signal handler grpc/grpc#24884 where the grpc maintainers closed this exact issue as "not a bug".While point 2 is trivial one is not so trivial in a portable way and sticking to C++17. The solution is to have the signal handler to report in some way to a "waiting" thread that is time to quit, this "report" in my knowledge could be done in several ways:
a) By means of a native C++ semaphore, if we were on C++20, but this is C++17
b) By means of a posix semaphore, but this means a named system-level resource with all that it implies (need to cleanup, uncomfortable situation if the server crashes without cleanup, ...)
c) By means of a volatile/atomic global variable, but as we do not have wait/notify in C++17 it means that the "killer" thread must poll it periodically, say once every second: two context switches every second and up to a one second delay for quitting.
d) By means of a mutex, but the interrupt handler MUST run in the same thread context that blocked the mutex initially (and in this case can safely release tthe mutex) while the "waiting killer" thread must be a separate one. Technically clean but not simple solution.
I can dedicate half an hour to sort this out and write the code, but I'd like to know in advance which solution among b-c-d is preferred.
If I were the maintainer I would go for d); in this case: yes, we have TWO "idle" threads dedicated to this, but they are really "idle" (will stay sleeping until the signal arrives.
Let me know,
A.
The text was updated successfully, but these errors were encountered: