Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spec says setReadOnly will throw an exception if in a transaction or if connection closed #311

Closed
davecramer opened this issue Jan 17, 2023 · 6 comments
Assignees

Comments

@davecramer
Copy link
Contributor

https://github.com/awslabs/aws-advanced-jdbc-wrapper/blob/dc3f1e96666ad394635fa3e2dcb9e0ca21214128/wrapper/src/main/java/software/amazon/jdbc/plugin/readwritesplitting/ReadWriteSplittingPlugin.java#L459

this method is called on a closed connection or this method is called during a transaction

@congoamz
Copy link
Contributor

Hi @davecramer, thanks for pointing this out, I've created a ticket to resolve this

@congoamz
Copy link
Contributor

congoamz commented Jan 18, 2023

Hi @davecramer, I've done some investigation and while the PG driver does follow the spec, MySQL allows users to call setReadOnly inside transactions without throwing an exception. With the current implementation, the plugin essentially just forwards the setReadOnly call to the underlying driver without doing anything special. So whether an exception is thrown or not depends on the underlying driver. I've chatted with the team and we are proposing to keep this implementation since throwing an exception here could break customer MySQL workflows, even if those workflows are a bit unusual. Let me know if you have any objections or if I can close this issue.

A small caveat: the plugin does throw an exception if setReadOnly(false) is called while connected to a reader and inside a transaction. This is because the user has indicated they want a read-write connection but we cannot switch to a writer, as we are already in a transaction. If setReadOnly(true) is called while in a transaction we just stick with the same connection and forward the call to the underlying driver.

@davecramer
Copy link
Contributor Author

@congoamz ugh :( Fair enough. So the next question is what to do about a connection that is closed.
https://github.com/awslabs/aws-advanced-jdbc-wrapper/blob/dc3f1e96666ad394635fa3e2dcb9e0ca21214128/wrapper/src/main/java/software/amazon/jdbc/plugin/readwritesplitting/ReadWriteSplittingPlugin.java#L465 has us doing something on a closed connection. This is also against contrary to the SPEC

@congoamz
Copy link
Contributor

@davecramer As is the plugin will get a new working connection in these scenarios. I can change this to throw an exception instead though

@davecramer
Copy link
Contributor Author

@congoamz I think it makes more sense to do this. Anyone calling methods on a closed connection has a broken app. I'm not sure we want to hide that from the developer.

congoamz pushed a commit that referenced this issue Jan 25, 2023
…closed connection (#318)

The JDBC setReadOnly javadocs specify that an exception should be thrown
if the method is called on a closed connection.

Related issue: #311
@congoamz
Copy link
Contributor

Just merged in a PR that throws an exception if setReadOnly is called on a closed connection, so I'll close this issue now

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

No branches or pull requests

2 participants