Skip to content

Handle EINTR exit codes from select - #516

Merged
MisterTea merged 1 commit into
MisterTea:masterfrom
jwmcglynn:select-eintr
May 2, 2022
Merged

MisterTea merged 1 commit into
MisterTea:masterfrom
jwmcglynn:select-eintr

Conversation

@jwmcglynn

Copy link
Copy Markdown
Collaborator

This fixes #503, where etserver crashed if select returned an EINTR error code. This is apparently normal behavior, and the caller is expected to retry when this occurs.

For codepaths that FATAL_FAIL on the select results, add special handling to retry instead of crashing. Note that the specific approach varies for each callsite.

Doing this impacts SIGINT, however, so to keep Ctrl-C working to exit the process fix, update the Sentry SIGINT handler so that it calls et::InterruptSignalHandler, enabling the process to exit semi-gracefully (however it still prints a callstack).

Testing

To test, first call etterminal and do not provide any input:

$ ./etterminal
Call etterminal with --idpasskey or --idpasskeyfile, or feed this information on stdin

Then launch etserver and verify it exits with Ctrl-C (or equivalent)

$ ./etserver --logtostdout -v 9
[INFO 2022-04-30 19:46:54,927 etserver-main TerminalServerMain.cpp:185] In child, about to start server.
[INFO 2022-04-30 19:46:54,928 etserver-main TcpSocketHandler.cpp:224] Listening on 0.0.0.0:2022/2/1/6
[INFO 2022-04-30 19:46:54,928 etserver-main TcpSocketHandler.cpp:224] Listening on 0.0.0.0:2022/10/1/6
[INFO 2022-04-30 19:46:54,928 etserver-main TerminalServer.cpp:23] Creating server
^CShutting down sentry
[ERROR 2022-04-30 19:46:57,863 etserver-main Headers.hpp:411] Stack Trace:
[0] 0x1b788f el::base::Writer& el::base::Writer::operator<< <ust::StackTrace>(ust::StackTrace const&) (easylogging++.h:3215)
[1] 0x1d05a3 et::TelemetryService::TelemetryService(bool, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)::{lambda(int)#2}::_FUN(int) (TelemetryService.cpp:190)
[2] 0x7f019558a210
[3] 0x7f019565c12b __select
[4] 0x1be4bf et::TerminalServer::run() (TerminalServer.cpp:63)
[5] 0x175a9f main (TerminalServerMain.cpp:195)
[6] 0x7f019556b0b3 __libc_start_main
[7] 0x17840e _start
Got interrupt

Got interrupt (perhaps ctrl+c?).  Exiting.

Shutting down sentry

This fixes MisterTea#503, where etserver crashed if select returned an EINTR error
code. This is apparently normal behavior, and the caller is expected to
retry when this occurs.

For codepaths that `FATAL_FAIL` on the select results, add special
handling to retry instead of crashing. Note that the specific
approach varies for each callsite.

Doing this impacts SIGINT, however, so to keep Ctrl-C working to
exit the process fix, update the Sentry SIGINT handler so that it
calls `et::InterruptSignalHandler`, enabling the process to exit
semi-gracefully (however it still prints a callstack).

# Testing

To test, first call `etterminal` and do not provide any input:
```
$ ./etterminal
Call etterminal with --idpasskey or --idpasskeyfile, or feed this information on stdin
```

Then launch `etserver` and verify it exits with Ctrl-C (or equivalent)
```
$ ./etserver --logtostdout -v 9
[INFO 2022-04-30 19:46:54,927 etserver-main TerminalServerMain.cpp:185] In child, about to start server.
[INFO 2022-04-30 19:46:54,928 etserver-main TcpSocketHandler.cpp:224] Listening on 0.0.0.0:2022/2/1/6
[INFO 2022-04-30 19:46:54,928 etserver-main TcpSocketHandler.cpp:224] Listening on 0.0.0.0:2022/10/1/6
[INFO 2022-04-30 19:46:54,928 etserver-main TerminalServer.cpp:23] Creating server
^CShutting down sentry
[ERROR 2022-04-30 19:46:57,863 etserver-main Headers.hpp:411] Stack Trace:
[0] 0x1b788f el::base::Writer& el::base::Writer::operator<< <ust::StackTrace>(ust::StackTrace const&) (easylogging++.h:3215)
[1] 0x1d05a3 et::TelemetryService::TelemetryService(bool, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)::{lambda(int)MisterTea#2}::_FUN(int) (TelemetryService.cpp:190)
[2] 0x7f019558a210
[3] 0x7f019565c12b __select
[4] 0x1be4bf et::TerminalServer::run() (TerminalServer.cpp:63)
[5] 0x175a9f main (TerminalServerMain.cpp:195)
[6] 0x7f019556b0b3 __libc_start_main
[7] 0x17840e _start
Got interrupt

Got interrupt (perhaps ctrl+c?).  Exiting.

Shutting down sentry
```
@MisterTea
MisterTea merged commit 3589b70 into MisterTea:master May 2, 2022
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.

core-dump on ubuntu20.04

2 participants