Skip to content

Bugfix/session office not set#1757

Draft
msweier wants to merge 4 commits into
USACE:developfrom
msweier:bugfix/session_office_not_set
Draft

Bugfix/session office not set#1757
msweier wants to merge 4 commits into
USACE:developfrom
msweier:bugfix/session_office_not_set

Conversation

@msweier
Copy link
Copy Markdown

@msweier msweier commented Jun 1, 2026

Summary

This is an AI assisted PR to help get the ball rolling on this bug fix.

Adds SessionOfficePreparer to the connection preparer chain in JooqDao.getDslContext(Context) so that every pooled connection gets its Oracle session office set on checkout.

I've seen intermittant 500 errors on develop CDA that traces to (ORA-20047: SESSION_OFFICE_ID_NOT_SET) on authenticated requests to the timeseries endpoint when multithreading a POR timeseries pull, but AI suggests this applies to all office scoped endpoints.

This may have been latent since 2022 but exposed with PR #1692 made it visible by switching timeseries reads from cwms_ts.retrieve_ts_out_tab (which handles office context internally) to a direct SQL path that calls CWMS_UTIL.CONVERT_UNITS inline. Non-authenticated requests ppear unaffected because AuthDao.prepareGuestContext() already wires in a SessionOfficePreparer; the authenticated path via prepareContextWithUser() doesn't.

Related Issue

Closes #1753

Validation

This is difficult to test. The failure depends on connection pool state, which connections are warm, what office they were last used for, and whether the pool has recycled them. AI couldn't reliably reproduce it in a single-threaded integration test, and even under concurrent load it only fails a fraction of the time. I am able to reporduce using a cwms-python POR query in develop, but I couldn't validate on a local instance.

The new JooqDaoTestIT does what it can: it verifies SessionOfficePreparer against the Oracle instance by checking that the session variable gets set on a cold connection and correctly overridden when switching offices, but it can't replicate the race conditions that causes the error. The tests also pass on the current develop branch since I couldn't replicate the error condition in the test enviorment.

If anyone has ideas for a better way to exercise the pool-level behavior, I'm all ears.

Checklist

  • AI tools used - Claude Opus 4.6

@msweier
Copy link
Copy Markdown
Author

msweier commented Jun 1, 2026

I updated the ClobControllerTest because it is the only mock setup that is building the request by hand and it needed to match the new context. The integration tests didn't needed because it is testing for real.

@rma-rripken
Copy link
Copy Markdown
Collaborator

rma-rripken commented Jun 1, 2026

Seems worth trying. If we're always setting the office here should SessionOfficePreparer get removed from the AuthDao?

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.

Intermitant 500 error reading timeseries when threading returns ORA-20047 / "Database Error" or "System Error"

2 participants