Commit Graph
38 Commits
Author SHA1 Message Date
Brad Arant c3e8d70774 Fix numerous thread/socket lifecycle crashes and TLS/epoll write-stall busy-loop
Thread/EPoll lifecycle:
- Thread::~Thread() now actually joins/frees its worker thread (was
  empty - the OS thread kept running against already-freed EPoll/Socket
  objects on any early teardown, a confirmed "double free" crash)
- EPoll::~EPoll() calls stop() if never explicitly stopped, for the
  same reason
- epoll_wait() now uses a 1s timeout instead of blocking forever, so a
  worker thread can actually notice isStopping() and let itself be
  joined
- EPoll::processCommand() iterated threads by value, silently
  double-freeing the real vector's Thread the moment each copy went
  out of scope
- ThreadScope gained onThreadStart()/onThreadEnd() hooks (actually
  wired up now - the constructor that was supposed to store the scope
  discarded it) for per-thread C-library init (e.g. MySQL client)

Socket/TCPSocket/TLS:
- Socket::writeSocket(): give up and shut down a connection after 50
  consecutive zero-progress sends instead of retrying forever -
  SSL_ERROR_WANT_READ on a write needs a READ to make progress, but
  resetSocket() re-arms EPOLLWRNORM regardless, which an
  already-writable TCP socket satisfies immediately - a real stuck
  connection generated 55GB, then 12.9GB of debug log this way before
  being caught
- Socket::writeSocket() now honors sendData()'s actual return value
  (previously discarded, entry popped unconditionally after one call) -
  a large response could get silently truncated past what fit in one
  write()/SSL_write() call
- TLS::registerSocket()/sendData()/receiveData(): `initialized` now
  only goes true once SSL_set_fd() has actually succeeded, and
  sendData()/receiveData() check it first - fixes a real SIGSEGV where
  a new session's own queued greeting could reach SSL_write() on a
  different epoll thread before this session's handshake setup had run
- TCPServer::connectionRequest() now performs the TLS handshake ON THE
  ACCEPTED SESSION, not the listening server itself (was building SSL
  state on the wrong object, leaving every session's own `ssl`
  uninitialized)
- TCPServer::receiveData() always uses the plain (non-TLS) read path -
  the listening socket is never itself a TLS peer
- TCPSocket's block-mode literal reading used an unset `blockLength`
  field instead of `blockSize`, and could busy-spin forever on a
  multi-packet literal
- TCPSocket line scanning replaced an unbounded strcspn() (assumes a
  NUL-terminated buffer; read past a non-NUL-terminated receive buffer
  into adjacent heap memory) with a bounds-checked memchr() scan

Protocol/session handling:
- CommandList::processRequest() now case-folds the command keyword
  before lookup - SMTP/POP3/IMAP commands are spec-required to be
  case-insensitive; a client sending "Mail From:" instead of
  "MAIL FROM:" previously failed to dispatch at all
- TCPSession::protocol() no longer drops blank lines while a handler
  has grabbed input (e.g. __SMTP_DATA reading a message body, an IMAP
  APPEND literal) - those handlers depend on seeing blank lines as
  real content, not commands; this silently corrupted any message body
  containing a blank line
- TCPSession's uuid alias fixed: streaming a raw uuid_t via operator<<
  triggered libstdc++'s unsigned-char* overload (strlen() on 16 binary
  bytes, a real stack-buffer-overflow read), and `alias` pointed at a
  stack-local that was already destroyed by the time the constructor
  returned
- INotify::processEvent() only treats event->name as a NUL-terminated
  string when event->len > 0 (per inotify(7)) instead of unconditional
  strlen() on a field the kernel doesn't guarantee is even present -
  a confirmed heap-buffer-overflow read that had been misdiagnosed as
  a MySQL thread-safety issue
2026-09-03 05:17:41 +00:00
Brad Arant a391882541 Made server a pointer for eliminating TCPSession2. 2024-07-30 15:59:25 -07:00
Brad Arant b7deabc5dc Rework for TLS. 2024-07-10 13:30:18 -07:00
Brad Arant b2bdb522b3 Minor code cleanup. 2024-07-09 15:01:53 -07:00
Brad Arant 0ef782a11c Added subscription to handler list so subscription can be accessed from handler. 2023-06-09 20:16:04 -07:00
Brad Arant b0118cfc56 subscriber work 2023-03-10 12:55:46 -08:00
Brad Arant 9b9e12d03c session 2023-03-08 13:56:52 -08:00
Brad Arant b63b4785cf Synced up to Matts code. 2023-02-11 17:24:25 -08:00
Brad Arant d8eb3d7bb2 merged in publish handlers. 2023-02-09 11:38:09 -08:00
Brad Arant f1d019e1e0 updated stuff. 2023-02-07 20:07:12 -08:00
Brad 1e76a7f49a setup ignore update for .history files. 2023-02-08 03:31:51 +00:00
Brad Arant 0dc5d5738e Fixed writing issue during write to another socket. 2022-10-25 20:33:50 -07:00
Brad Arant fd70c79282 Create TCPSession2 for outpubound connections. 2022-10-17 20:03:23 -07:00
Brad Arant 9af17daed6 Fixing command list delimiter depth. 2022-07-26 16:07:37 -07:00
Brad Arant d13e3f9fb5 Got the subscription event scope parameter added. 2022-02-13 00:23:56 +00:00
Brad Arant 3ef82e0fce Compiles 2022-01-24 18:36:47 -08:00
Brad Arant ec39c1df1a Added subscription service capability. 2021-08-31 17:57:21 -07:00
Brad Arant 0a03b3553d Latest build 2021-08-26 22:57:07 -07:00
barant 608f8a2b0c Update changes. 2021-08-14 15:03:43 -07:00
Brad Arant 86bd62221f Merge branch 'develop' of ssh://barant.com/git/ServerCore into develop 2021-08-11 21:59:25 -07:00
Brad Arant b7398afc05 It works!!! 2021-08-11 21:38:22 -07:00
Brad Arant 43489e5b3a Updated code 2021-08-08 10:47:55 -07:00
Brad Arant 20d5c99517 Working Version 2021-08-07 11:47:54 -07:00
Brad Arant 46f98dff69 Many changes 2021-08-05 13:07:53 -07:00
barant d445834af6 Many changes to ServerCore 2021-07-23 08:57:27 -07:00
Brad Arant bcea21cf96 Got it compiling and somewhat working, except post. 2020-11-29 13:57:06 -08:00
Brad Arant 7ee13e87d2 Sync. 2020-11-16 17:00:08 -08:00
Brad Arant 054eb40c2b Added vscode 2020-11-07 17:30:25 -08:00
Brad Arant f652ba1f34 Added vscode 2020-11-07 17:28:24 -08:00
barant b6546cd0dd Sync. 2020-10-27 14:40:15 -07:00
barant 177bc602af Working on block receive capability. 2020-10-20 10:53:06 -07:00
barant 3fee297136 Move docs around. 2020-06-11 18:54:51 -07:00
Brad Arant 796ddd511f A commit before I change everything on the the way events are handled. 2020-04-25 08:19:26 -07:00
barant 28292e924a Continued improvements to shutdown. 2020-04-23 14:25:41 -07:00
barant b4ab5fb86a New build. 2020-04-13 09:40:58 -07:00
barant a5a51f8aae Major changes to socket scheduling in EPoll. 2020-02-29 19:27:58 -08:00
barant d373a2e4a0 Alsmost TLS 2019-09-21 13:07:18 -07:00
barant a40f7314a8 Elimination of Service object, 2019-09-18 18:32:15 -07:00