You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The currentTenant value in the TenantIdentifierResolver.java file is not thread-safe, which can lead to issues in a multi-threaded environment where concurrent requests are handled.
Problem:
The currentTenant variable is shared across multiple threads, which can cause race conditions and inconsistent behavior when multiple requests are processed concurrently.
Steps to Reproduce:
Deploy the application in a multi-threaded environment.
Send multiple concurrent requests that rely on the currentTenant value.
Expected Result:
Each request should have its own isolated currentTenant value.
Actual Result:
The currentTenant value is shared across threads, leading to potential data corruption and inconsistent behavior.
Suggested Fix:
Consider using a ThreadLocal variable to store the currentTenant value for each thread independently. This will ensure that each request has its own isolated currentTenant value.
This is purely an example how to integrate Hibernate multi tenancy features with Spring Data JPA. I assumed it would be obvious that for a real application one needs do decide on the appropriate scope of the currentTenant. I'll add a comment to that effect to the readme.
The
currentTenant
value in the TenantIdentifierResolver.java file is not thread-safe, which can lead to issues in a multi-threaded environment where concurrent requests are handled.Problem:
The
currentTenant
variable is shared across multiple threads, which can cause race conditions and inconsistent behavior when multiple requests are processed concurrently.spring-data-examples/jpa/multitenant/schema/src/main/java/example/springdata/jpa/hibernatemultitenant/schema/TenantIdentifierResolver.java
Lines 28 to 37 in 9988a78
Steps to Reproduce:
Deploy the application in a multi-threaded environment.
Send multiple concurrent requests that rely on the
currentTenant
value.Expected Result:
Each request should have its own isolated
currentTenant
value.Actual Result:
The currentTenant value is shared across threads, leading to potential data corruption and inconsistent behavior.
Suggested Fix:
Consider using a ThreadLocal variable to store the
currentTenant
value for each thread independently. This will ensure that each request has its own isolatedcurrentTenant
value.Example:
The text was updated successfully, but these errors were encountered: