Skip to content

Handle SQL connection initialization failures safely - #111

Merged
BenCodez merged 3 commits into
mainfrom
fix/sql-initialization-lifecycle
Oct 11, 2026
Merged

BenCodez merged 3 commits into
mainfrom
fix/sql-initialization-lifecycle

Conversation

@BenCodez

@BenCodez BenCodez commented Oct 11, 2026 •

Copy link
Copy Markdown
Owner

A rejected SQL pool currently allows table construction to continue and invoke subclass logging before subclass fields are initialized. Abort connection/database-selection setup with the original exception, skip subsequent queries, and disconnect resources owned by an aborted table constructor. Successful external connection diagnostics and legacy asynchronous recovery after a temporary connection failure remain supported.

The existing public entry point remains available. The additive diagnostics-free overload allows constructor setup without virtual logging callbacks. Database identifiers use the existing dialect-aware escaping helper. No storage fallback, schema change, dependency upgrade or configuration migration.

Validation (JDK 21 target, isolated local Maven repository):

  • Focused initialization/pool regressions: 17 passed.
  • Full mvn -B -o -ntp -f SimpleAPI/pom.xml clean install: 464 passed, one optional skip, zero failures/errors; full and shared JARs produced and inspected.
  • CI compatibility invocation with -Plegacy-mysql-tls-test -Dtest=MariaDbFallbackTlsTest test: nine passed.
  • AdvancedCore consumer full suite: 1,029 passed; VotingPlugin consumer full package: 1,975 passed, one skip, against the exact candidate dependency artifacts.
  • Fresh independent read-only review: No findings. git diff --check passed.

Authentication rejection is simulated by an in-process JDBC driver through real Hikari initialization; tests cover original causes, no premature hooks/queries, failed database selection, quoted database names and successful asynchronous update/batch recovery. This is automated testing, not a live external MySQL or visually verified gameplay test.

Build/dependency order: SimpleAPI first, then the paired AdvancedCore fix, then the final VotingPlugin JAR. Paired fixes: AdvancedCore #361 and VotingPlugin #1701. Consumer PRs remain draft until corrected dependencies are available to hosted builds. Changes are modern repositories only.

Follow-up regressions also verify failed public-connect debug output without credentials and unchanged runtime/fatal JDBC exception identity after cleanup. Hosted initial build passed; the new head is awaiting its own checks.

SQL worker cleanup follow-up (cd3f650): disconnect now attempts worker retirement even if pool closure throws, preserving the original failure and suppressing a second cleanup failure. Regression coverage includes successful cleanup, RuntimeException/Error failures from each resource, both failing, pre-connect shutdown and repeated shutdown.

Validation against the exact corrected producer/consumer artifacts:

  • Focused SQL lifecycle suite: 19 passed.
  • SimpleAPI clean install: 466 passed, 1 optional test skipped, no failures/errors; full and shared JAR boundaries inspected.
  • AdvancedCore clean install: 1,029 passed, no failures/errors/skips.
  • VotingPlugin lifecycle-focused suite: 129 passed; clean distributable build: 1,975 passed, 1 optional skip, no failures/errors.
  • GraveStonesPlus consumer validation: 43 focused and 374 full-suite tests passed after its compatible bootstrap guard follow-up.
  • Fresh independent read-only SimpleAPI follow-up review: No findings. git diff --check passed.
  • Hosted build and CodeQL pass for this head. CodeRabbit reports that review was skipped; that is not a completed source review.

These are automated mocked/unit and artifact checks, not a live MySQL authentication test. AdvancedCore #361 and VotingPlugin #1701 still require the corrected dependency artifacts to be available to their hosted builds. No release or deployment was performed.

@coderabbitai

coderabbitai Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8022595c-5da3-46c1-8364-5e66412b0715

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-11T06:19:27.433216Z cd3f650 New commits
🔒 Security Review ✅ Completed 2026-10-11T05:12:49.372315Z 86aa5f5 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 86aa5f5e54

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

// disconnects explicitly when construction is aborted instead.
}

if (ok && emitDiagnostics && config.isDebug()) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve failure diagnostics for public connect

When config.isDebug() is true and ConnectionManager.open() returns false, the existing public connect(config) path used to invoke the subclass's failure logger, but this success-only condition now returns false silently. getLastConnectFailure() does not preserve that callback behavior for existing consumers; apply emitDiagnostics to both outcomes while keeping the constructor-only call silent.

AGENTS.md reference: AGENTS.md:L33-L36

Useful? React with 👍 / 👎.

Comment on lines +148 to +151
} catch (SQLException | RuntimeException | Error failure) {
try { mysql.disconnect(); }
catch (RuntimeException | Error cleanupFailure) { failure.addSuppressed(cleanupFailure); }
throw new IllegalStateException("Failed to initialize SQL database selection", failure);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Rethrow unchecked database-selection failures unchanged

If a JDBC driver throws a RuntimeException or the JVM raises an Error while preparing or executing USE, this catch converts it to IllegalStateException; previously those unchecked failures propagated unchanged, and wrapping an Error can also defeat fatal-error handling. Perform cleanup but rethrow the original unchecked failure, reserving the initialization wrapper for the checked SQLException path.

AGENTS.md reference: AGENTS.md:L44-L46

Useful? React with 👍 / 👎.

@BenCodez
BenCodez merged commit fdbf26e into main Oct 11, 2026
5 checks passed
@BenCodez
BenCodez deleted the fix/sql-initialization-lifecycle branch October 11, 2026 16:13
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.

1 participant