Skip to content
New issue

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

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

Already on GitHub? # to your account

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

Closed
mohamedmelfiky opened this issue Jan 23, 2024 · 0 comments
Closed
Assignees
Labels
type: bug A general bug

Comments

@mohamedmelfiky
Copy link

Environment:

  • Spring Boot: 3.2.1
  • spring-boot-starter-data-cassandra (which brings starter version 3.2.1 and data cassandra version 4.2.1)
  • Java: 17
  • Cassandra: 5.0

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.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 23, 2024
@mp911de mp911de self-assigned this Jan 24, 2024
@mp911de mp911de added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Jan 24, 2024
@mp911de mp911de changed the title potential memory leak with @Column annotation Constructor with @Column-annotated arguments leads to memory leak Jan 24, 2024
@mp911de mp911de added this to the 4.1.9 (2023.0.9) milestone Jan 24, 2024
mp911de added a commit that referenced this issue Jan 24, 2024
…and properties.

We now provide equals/hashCode and selective caching for derived properties and entities derived from embedded properties and constructor-annotated properties to avoid memory leaks using properties and entities as cache keys.

Closes #1471
mp911de added a commit that referenced this issue Jan 24, 2024
…and properties.

We now provide equals/hashCode and selective caching for derived properties and entities derived from embedded properties and constructor-annotated properties to avoid memory leaks using properties and entities as cache keys.

Closes #1471
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants