GitHub user zsxwing opened a pull request:

    https://github.com/apache/spark/pull/22062

    [SPARK-25081][Core]Nested spill in ShuffleExternalSorter should not access 
released memory page

    ## What changes were proposed in this pull request?
    
    This issue is pretty similar to 
[SPARK-21907](https://issues.apache.org/jira/browse/SPARK-21907). 
    
    "allocateArray" in 
[ShuffleInMemorySorter.reset](https://github.com/apache/spark/blob/9b8521e53e56a53b44c02366a99f8a8ee1307bbf/core/src/main/java/org/apache/spark/shuffle/sort/ShuffleInMemorySorter.java#L99)
 may trigger a spill and cause ShuffleInMemorySorter access the released 
`array`. Another task may get the same memory page from the pool. This will 
cause two tasks access the same memory page. When a task reads memory written 
by another task, many types of failures may happen. Here are some examples I  
have seen:
    
    - JVM crash. (This is easy to reproduce in a unit test as we fill newly 
allocated and deallocated memory with 0xa5 and 0x5a bytes which usually points 
to an invalid memory address)
    - java.lang.IllegalArgumentException: Comparison method violates its 
general contract!
    - java.lang.NullPointerException at 
org.apache.spark.memory.TaskMemoryManager.getPage(TaskMemoryManager.java:384)
    - java.lang.UnsupportedOperationException: Cannot grow BufferHolder by size 
-536870912 because the size after growing exceeds size limitation 2147483632
    
    This PR resets states in `ShuffleInMemorySorter.reset` before calling 
`allocateArray` to fix the issue.
    
    ## How was this patch tested?
    
    The new unit test will make JVM crash without the fix.


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/zsxwing/spark SPARK-25081

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/spark/pull/22062.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #22062
    
----
commit 54799cae8ef0727988bbb863d326ea61b4d9ae72
Author: Shixiong Zhu <zsxwing@...>
Date:   2018-08-10T00:02:33Z

    Nested spill in ShuffleExternalSorter should not access released memory page

----


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to