aminghadersohi opened a new pull request, #39917: URL: https://github.com/apache/superset/pull/39917
### SUMMARY MCP tools running in thread-pool workers (sync tools) call `db.session.remove()` before each invocation to clear any stale thread-local session. If the underlying DBAPI connection died between requests — e.g. RDS dropped it due to SSL idle-timeout or max-connection-age — the implicit `rollback()` inside `session.close()` raises `OperationalError`. This caused the tool call to fail with a stack trace, even when the operation itself had completed successfully. **Root cause:** `sync_wrapper` in `auth.py` called `db.session.remove()` bare, with no handling for connection-level errors. **Fix:** Extract `_remove_session_safe()` which: 1. Catches `OperationalError` from `session.remove()` 2. Calls `session.invalidate()` to mark the dead connection for pool discard (prevents it being checked out again by another thread) 3. Retries `session.remove()` to deregister the scoped session The tool call proceeds normally; a fresh connection is obtained on the next DB access. ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF N/A — backend-only change ### TESTING INSTRUCTIONS 1. Unit test: `pytest tests/unit_tests/mcp_service/test_auth_user_resolution.py::test_sync_wrapper_handles_ssl_error_on_pre_call_remove` 2. To reproduce manually: configure a short RDS SSL idle timeout, make an MCP tool call after an idle period — observe no error in logs. ### ADDITIONAL INFORMATION - [ ] Has associated issue: - [ ] Required feature flags: - [ ] Changes UI - [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351)) - [ ] Migration is atomic, supports rollback & is backwards-compatible - [ ] Confirm DB migration upgrade and downgrade tested - [ ] Runtime estimates and downtime expectations provided - [ ] Introduces new feature or API - [ ] Removes existing feature or API -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
