spring-projects / spring-data-cassandra

Provides support to increase developer productivity in Java when using Apache Cassandra. Uses familiar Spring concepts such as a template classes for core API usage and lightweight repository style data access.
https://spring.io/projects/spring-data-cassandra/
Apache License 2.0
373 stars 307 forks source link

Constructor with `@Column`-annotated arguments leads to memory leak #1471

Closed mohamedmelfiky closed 5 months ago

mohamedmelfiky commented 5 months ago

Environment:

Hi when i use @Column in my entities like below

@Table("customers")
public record Customer(
        @PrimaryKey Integer msisdn,
        @Column("firebase_token") String firebaseToken,
        Map<String, @Frozen CustomerSegment> segments,
        Map<String, String> status
) {}

@UserDefinedType("segment")
public record CustomerSegment(
        @Column("segment_id") Integer segmentId,
        @Column("last_updated_at") LocalDateTime lastUpdatedAt,
        @Column("is_active") Boolean isActive
) { }

i saw the heap started to grow and not claimed again. i tried to investigate as much as i could and found that in MappingCassandraConverter class

 @Nullable
private CassandraPersistentProperty getPersistentProperty(String name, TypeInformation<?> typeInformation,
                MergedAnnotations annotations) {

    CassandraPersistentProperty property = entity.getPersistentProperty(name);

    if (annotations.isPresent(Column.class) || annotations.isPresent(Element.class)) {
        return new AnnotatedCassandraConstructorProperty(
                property == null ? new CassandraConstructorProperty(name, entity, typeInformation) : property, annotations);
    }

    return property;
}

when the property has column annotation it create a new AnnotatedCassandraConstructorProperty and eventually check if it has a converter in the cache in CachingPropertyValueConverterFactory class which will return null for every new AnnotatedCassandraConstructorProperty and save it in the cache. The heap will start to grow and never reclaimed and the service started to hung up and eventually OOM.

i searched if this issue already exist but i could not found any.

sorry if i am not very clear.