Overview
YAML serialization can race with file content persistence, potentially causing data corruption or inconsistency.
Location
File: intellij-plugin/hs-core/src/org/hyperskill/academy/learning/storage/LearningObjectsStorageManager.kt
Function: EduFile.persist (lines 42-91)
Problem
The code persists file contents on a pooled thread but doesn't properly synchronize YAML serialization. The comment on lines 137-138 says "This should be called before YAML serialization to avoid race conditions" but there's no enforcement mechanism.
// This should be called before YAML serialization to avoid race conditions
fun waitForPersistingTasks() {
// Called manually but no guarantee it happens before save
}
What needs to be fixed
- The
waitForPersistingTasks() function (lines 140-152) is called manually but there's no guarantee it's called before YAML serialization
- Add a listener or hook to ensure
waitForPersistingTasks() is automatically called before YAML serialization
- Consider using
CompletableFuture instead of raw Future for better composition
- Add proper error handling for cases where contents change during persistence (lines 72-85)
Tests understanding of
- Concurrent programming and race conditions
- Future/CompletableFuture patterns
- IntelliJ's message bus system or save listeners
- File content synchronization strategies
Validation
- Write a test that rapidly modifies files and triggers saves
- Ensure no corruption or data loss occurs
- Verify that persistence completes before YAML serialization
Estimated time
4-5 hours
Overview
YAML serialization can race with file content persistence, potentially causing data corruption or inconsistency.
Location
File:
intellij-plugin/hs-core/src/org/hyperskill/academy/learning/storage/LearningObjectsStorageManager.ktFunction:
EduFile.persist(lines 42-91)Problem
The code persists file contents on a pooled thread but doesn't properly synchronize YAML serialization. The comment on lines 137-138 says "This should be called before YAML serialization to avoid race conditions" but there's no enforcement mechanism.
What needs to be fixed
waitForPersistingTasks()function (lines 140-152) is called manually but there's no guarantee it's called before YAML serializationwaitForPersistingTasks()is automatically called before YAML serializationCompletableFutureinstead of rawFuturefor better compositionTests understanding of
Validation
Estimated time
4-5 hours