Github user rxin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/3259#discussion_r20400513
  
    --- Diff: 
core/src/main/scala/org/apache/spark/network/nio/ConnectionManager.scala ---
    @@ -899,22 +904,41 @@ private[nio] class ConnectionManager(
           : Future[Message] = {
         val promise = Promise[Message]()
     
    -    val timeoutTask = new TimerTask {
    -      override def run(): Unit = {
    +    // It's important that the TimerTask doesn't capture a reference to 
`message`, which can cause
    +    // memory leaks since cancelled TimerTasks won't necessarily be 
garbage collected until the time
    +    // at which they would originally be scheduled to run.  Therefore, 
extract the message id
    +    // from outside of the TimerTask closure (see SPARK-4393 for more 
context).
    +    val messageId = message.id
    +    // Keep a weak reference to the promise so that the completed promise 
may be garbage-collected
    +    val promiseReference = new WeakReference(promise)
    +    val timeoutTask: TimerTask = new TimerTask {
    +      override def run(timeout: Timeout): Unit = {
             messageStatuses.synchronized {
    -          messageStatuses.remove(message.id).foreach ( s => {
    +          messageStatuses.remove(messageId).foreach ( s => {
    --- End diff --
    
    nitpick here - u can remove one layer of parenthesis/brackets
    ```scala
    messageStatuses.remove(messageId).foreach { s =>
    
    }
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

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

Reply via email to