Kurly Resolves ByteBuffer Concurrency Error in AWS KMS Encryption SDK
Key point
Kurly resolved a ByteBuffer concurrency error occurring in its AWS KMS-based encryption SDK using the duplicate() method.
Details
Kurly operates a common encryption SDK module that applies enveloping encryption using AWS KMS for personal information protection law compliance, and has introduced a Caffeine cache to reduce costs. However, a newPosition > limit error was found to occur intermittently on the 1:1 inquiry board and other places, causing masked phone numbers to be displayed as blank to customers.
Cause of the Concurrency Error
The error occurred inside the get(byte[] dst) method of ByteBuffer. According to the Java API documentation, Buffer is not safe in a multi-threaded environment (not thread-safe). Testing confirmed that when multiple threads shared the Plaintext ByteBuffer of the same GenerateDataKeyResult object, the position values collided, causing the buffer's limit (32 bytes) to be exceeded.
Solution
After reviewing two solutions, the development team adopted the use of the duplicate() method. Adding a synchronized block was excluded as it could cause performance degradation; instead, calling duplicate() to create an independent buffer object for each thread resolved the concurrency issue. This operates on a similar principle to asReadOnlyBuffer(), which is recommended in the AWS SDK Javadoc.
This summary was generated automatically by AI. Check the original for the author's claims and context. Copyright belongs to the original author.
Our guide explains how the AI works. Report summary errors, attribution issues, or removal requests via Contact.