JoshRosen commented on a change in pull request #25953: [SPARK-29244][Core] 
Prevent freed page in BytesToBytesMap free again
URL: https://github.com/apache/spark/pull/25953#discussion_r329890079
 
 

 ##########
 File path: 
core/src/test/java/org/apache/spark/unsafe/map/AbstractBytesToBytesMapSuite.java
 ##########
 @@ -726,4 +727,21 @@ public void avoidDeadlock() throws InterruptedException {
     }
   }
 
+  @Test
+  public void freeAfterFailedReset() {
+    memoryManager.limit(5000);
+    BytesToBytesMap map =
+            new BytesToBytesMap(taskMemoryManager, blockManager, 
serializerManager, 256, 0.5, 4000);
+    // Force OOM on next memory allocation.
+    memoryManager.markExecutionAsOutOfMemoryOnce();
+    try {
+      map.reset();
+      Assert.fail("Expected SparkOutOfMemoryError to be thrown");
+    } catch (SparkOutOfMemoryError e) {
+      // Expected exception; do nothing.
+    } finally {
+      map.free();
+    }
 
 Review comment:
   Even though this test suite fails without the `longArray = null` change, it 
turns out that another (wrong!) way to make this test would be to simply remove 
the `free(longArray)` call and leak memory.
   
   Unfortunately, though, that doesn't cause the test to fail! It turns out 
that the 
   
   ```java
     @After
     public void tearDown() {
       Utils.deleteRecursively(tempDir);
       tempDir = null;
   
       if (taskMemoryManager != null) {
         Assert.assertEquals(0L, taskMemoryManager.cleanUpAllAllocatedMemory());
         long leakedMemory = 
taskMemoryManager.getMemoryConsumptionForThisTask();
         taskMemoryManager = null;
         Assert.assertEquals(0L, leakedMemory);
       }
     }
   ```
   
   doesn't work as expected because `TestMemoryManager` doesn't properly 
implement per-taskAttemptId memory-consumption tracking.
   
   I've opened #25985 to fix that problem. That doesn't need to block merging 
of this patch, however.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to