Commit graph

3 commits

Author SHA1 Message Date
Stephen Dennis
5eeecdcf03 sqlslave: surface connection/query failures instead of dropping them
Address the remaining medium/low SQLSlave issues:

- #749: add a dedicated QS_CONNECT_FAILED result code so softcode can tell
  "unreachable" from "connection refused/bad credentials". ConnectionHelper()
  now returns whether a live session was established; Query() maps a failed
  reconnect to QS_CONNECT_FAILED and a still-dead ping to QS_SQL_UNAVAILABLE.
  fun_rserror() renders it as "#-5 CONNECT_FAILED".
- #750: capture mysql_next_result() > 0 (error) while draining stored-procedure
  result sets and report QS_QUERY_ERROR rather than silently succeeding.
- #751: check the return value of every mysql_options() call.
- #752: remove the empty thread-id "detected reconnection" block (dead code);
  the charset option is reapplied by the client across auto-reconnect.
- #753: narrow the two component-allocation catch(...) blocks to
  catch(std::bad_alloc) so non-allocation exceptions are no longer masked.

Errors are logged via a best-effort ILog acquired in FinalConstruct(); when
the component runs in the slave process (no CID_Log there) logging is skipped
and the result codes still propagate to softcode.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-05 15:12:13 -06:00
Stephen Dennis
bad69fb9aa sqlslave: fix ref-count races, buffer ownership, and MySQL build break
Address the high-priority SQLSlave issues plus a latent compile error that
only surfaces once HAVE_MYSQL is enabled:

- #745: CQueryServer/CQueryServerFactory m_cRef -> std::atomic<uint32_t>
  with fetch_add(relaxed)/fetch_sub(acq_rel), matching comsys/mail. Closes
  the decrement/zero-check double-delete race.
- #746: g_cComponents/g_cServerLocks -> std::atomic<int32_t>.
- #747: Connect() rejects null server/database/user/password rather than
  letting mysql_real_connect() and ConnectionHelper() dereference them.
- #748: copy the connection parameters into module-owned std::strings
  instead of aliasing and delete[]-ing the caller's buffers. The old code
  delete[]'d mudconf-owned storage in-process and stack buffers across the
  proxy/stub boundary (lib/libmux.cpp CQueryControlStub::Invoke).
- #764: mysql_real_query() was called with a const-stripping
  reinterpret_cast<char *> on a const UTF8 *, a hard -std=c++17 error that
  broke the build whenever a MySQL client library is present. Cast to
  const char * (the parameter type) instead.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-05 15:00:16 -06:00
Stephen Dennis
4ff1398de1 Restructure mux/ directory: component-based layout with proper build root
Move from flat mux/src/ layout to clean component hierarchy:
- mux/ is now the autoconf/automake build root (configure.ac lives here)
- mux/include/ — shared headers used by multiple components
- mux/lib/ — libmux.so (core utilities, no game state)
- mux/src/ — netmux driver only (thin networking shell)
- mux/modules/engine/ — engine.so (game logic)
- mux/modules/{comsys,mail,exp3,sqlproxy,sqlslave}/ — external modules
- mux/ganl/ — GANL networking library
- mux/sqlite/ — SQLite amalgamation (builds libsqlite3.a)
- mux/announce/ — announce tool (was mux/src/tools/)

Build changes:
- SUBDIRS ordering: ganl sqlite lib src modules announce
- libmux.so gets -Wl,-soname,libmux.so; netmux links via -L -lmux
- engine.so links libsqlite3.a and libmux.so with -Wl,--no-undefined
- RPATH uses $ORIGIN for portable .so resolution
- Install hooks use absolute paths for game/bin symlinks

Bug fixes:
- engine.so mux_Register() now passes nullptr to mux_RegisterClassObjects
  (matches all other modules; libmux already has the factory via dlsym)
- DbConvert() now calls pcache_init() before db_write, fixing a latent
  crash (free(): invalid pointer) when exporting from SQLite databases

411/411 smoke tests pass.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 20:38:37 -06:00
Renamed from mux/src/modules/sqlslave.cpp (Browse further)