On 9/23/21 12:53 PM, eugene wrote:
>On Thursday, 23 September 2021 at 15:53:37 UTC, Steven Schveighoffer wrote:
>Technically, they should live past the end of main, because it's still possible to receive signals then.
No, as soon as an application get SIGTERM/SIGINT,
event queue is stopped and we do not need no
more notifications from OS (POLLIN/POLLOUT I mean).
Stopping event queue in this case is just
closing file descriptor obtained from epoll_create().
After this getting POLLIN from any fd (including signal fd) is
just impossible.
That's not what is triggering the segfault though. The segfault is triggered by the signal handler referencing the destroyed object.
So imagine the sequence:
- ctrl-c, signal handler triggers, shutting down the loop
- main exits
- GC finalizes all objects, including the Stopper and it's members
- ctrl-c happens again, but you didn't unregister the signal handler, so it's run again, referencing the now-deleted object.
- segfault
It's theoretically a very very small window.
-Steve