Skip to content

base: Fix etserver crash on transient accept() errors - #756

Merged
MisterTea merged 2 commits into
MisterTea:masterfrom
psaab:freebsd-fix
Jun 5, 2026
Merged

MisterTea merged 2 commits into
MisterTea:masterfrom
psaab:freebsd-fix

Conversation

@psaab

@psaab psaab commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

UnixSocketHandler::accept() called FATAL_FAIL on any accept() errno other than EAGAIN/EWOULDBLOCK, aborting the entire server. accept(2) routinely returns benign per-connection errors -- notably ECONNABORTED (the peer reset the connection before we accepted it) and EINTR. These are surfaced readily on FreeBSD by clients that connect and immediately disconnect (keepalive/reconnect churn), crashing etserver.

Treat EAGAIN, EWOULDBLOCK, ECONNABORTED, and EINTR as non-fatal and return -1; the accept loop already handles this by retrying. Genuinely unexpected errnos still fail fatally.

Backtrace on FreeBSD:

#0 thr_kill () at thr_kill.S:4
#1 __raise (s=s@entry=6) at /usr/src/lib/libc/gen/raise.c:50
#2 abort () at /usr/src/lib/libc/stdlib/abort.c:64
#3 el::base::utils::abort (status=1, reason="Fatal log at [.../src/base/UnixSocketHandler.cpp:146] ...")
at external_imported/easyloggingpp/src/easylogging++.cc:125
#4 el::base::Writer::triggerDispatch () at external_imported/easyloggingpp/src/easylogging++.cc:2653
#5 el::base::Writer::processDispatch () at external_imported/easyloggingpp/src/easylogging++.cc:2616
#6 el::base::Writer::~Writer () at external_imported/easyloggingpp/src/easylogging++.h:3209
#7 et::UnixSocketHandler::accept (this=..., sockFd=10) at src/base/UnixSocketHandler.cpp:146
#8 et::ServerConnection::acceptNewConnection (this=..., fd=10) at src/base/ServerConnection.cpp:17
#9 et::TerminalServer::run (this=...) at src/terminal/TerminalServer.cpp:79
#10 main (argc=6, argv=...) at src/terminal/TerminalServerMain.cpp:203

@codecov

codecov Bot commented Jun 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.37%. Comparing base (3f2109f) to head (9a5869d).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #756      +/-   ##
==========================================
+ Coverage   87.27%   87.37%   +0.10%     
==========================================
  Files          71       72       +1     
  Lines        5368     5395      +27     
  Branches      501      502       +1     
==========================================
+ Hits         4685     4714      +29     
+ Misses        682      681       -1     
+ Partials        1        0       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

UnixSocketHandler::accept() called FATAL_FAIL on any accept() errno
other than EAGAIN/EWOULDBLOCK, aborting the entire server. accept(2)
routinely returns benign per-connection errors -- notably ECONNABORTED
(the peer reset the connection before we accepted it) and EINTR. These
are surfaced readily on FreeBSD by clients that connect and immediately
disconnect (keepalive/reconnect churn), crashing etserver.

Treat EAGAIN, EWOULDBLOCK, ECONNABORTED, and EINTR as non-fatal and
return -1; the accept loop already handles this by retrying. Genuinely
unexpected errnos still fail fatally.

Backtrace on FreeBSD:

  #0  thr_kill () at thr_kill.S:4
  MisterTea#1  __raise (s=s@entry=6) at /usr/src/lib/libc/gen/raise.c:50
  MisterTea#2  abort () at /usr/src/lib/libc/stdlib/abort.c:64
  MisterTea#3  el::base::utils::abort (status=1, reason="Fatal log at [.../src/base/UnixSocketHandler.cpp:146] ...")
      at external_imported/easyloggingpp/src/easylogging++.cc:125
  MisterTea#4  el::base::Writer::triggerDispatch () at external_imported/easyloggingpp/src/easylogging++.cc:2653
  MisterTea#5  el::base::Writer::processDispatch () at external_imported/easyloggingpp/src/easylogging++.cc:2616
  MisterTea#6  el::base::Writer::~Writer () at external_imported/easyloggingpp/src/easylogging++.h:3209
  MisterTea#7  et::UnixSocketHandler::accept (this=..., sockFd=10) at src/base/UnixSocketHandler.cpp:146
  MisterTea#8  et::ServerConnection::acceptNewConnection (this=..., fd=10) at src/base/ServerConnection.cpp:17
  MisterTea#9  et::TerminalServer::run (this=...) at src/terminal/TerminalServer.cpp:79
  MisterTea#10 main (argc=6, argv=...) at src/terminal/TerminalServerMain.cpp:203
Add unit tests for UnixSocketHandler::isTransientAcceptError(), the helper
that decides which accept() errnos are recoverable. This exercises the
ECONNABORTED and EINTR cases (the FreeBSD crash) directly, plus EAGAIN/
EWOULDBLOCK, and confirms genuine errors (EBADF, EINVAL, ...) stay fatal.

Also add an end-to-end check that accept() on a non-blocking listening
socket with no pending connection returns -1 instead of aborting.
@MisterTea
MisterTea merged commit c6650d9 into MisterTea:master Jun 5, 2026
24 of 29 checks passed
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.

2 participants