Skip to content

Prevent possible race condition on IAM token expiry #612

@chlunde

Description

@chlunde

Describe the feature

We had some DB connections fail after when using this driver and IAM authentication. This was fixed by 2.1.2 and newer via #456 and #457.

But I don't think this code path should have triggered at all, because tokens should be refreshed in time.

In the logs, we still see a few "pam_authenticate failed: Permission denied" every hour. This will be very confusing when diagnosing other issues. I also expect

Use Case

No unnecessary reconnects, stable latency. No confusing log messages about expired token.

Proposed Solution

I would expect there to be a small grace period to prevent "TOCTTOU" race conditions, where the client code thinks it is valid when checking it, but the token is invalid when the server side receives and validates it.

This code uses exactly 900 seconds as a default. Subtracting somewhere between 2-30 seconds should be enough.

https://github.com/awslabs/aws-advanced-jdbc-wrapper/blob/708d8a240ef2cca9a7fc993f940688369374f26b/wrapper/src/main/java/software/amazon/jdbc/plugin/IamAuthConnectionPlugin.java#L53-L54

This should also improve P99 latencies.

You could also consider background refreshes, but I'm not sure if that's a good idea, it certainly adds complexity.

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

The AWS Advanced JDBC Driver version used

2.1.2+

JDK version used

17

Operating System and version

bottlerocket

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions