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

    https://github.com/apache/spark/pull/2019#discussion_r16732261
  
    --- Diff: 
core/src/main/scala/org/apache/spark/network/ConnectionManager.scala ---
    @@ -334,17 +338,23 @@ private[spark] class ConnectionManager(
                   while (allKeys.hasNext) {
                     val key = allKeys.next()
                     try {
    -                  if (! key.isValid) {
    -                    logInfo("Key not valid ? " + key)
    -                    throw new CancelledKeyException()
    +                  key.synchronized {
    +                    val connection = connectionsByKey.getOrElse(key, null)
    +                    if (key.channel.isInstanceOf[ServerSocketChannel] ||
    +                      connection != null && !connection.isClosed) {
    +                      if (!key.isValid) {
    --- End diff --
    
    You can still merge the conditions. Your code is racy with the connection 
being closed regardless of whether you have one or two ifs here.
    
    You can get rid of the weird check by doing:
    
        if ((connection == null || !connection.isClosed) && !key.isValid) { 
throw ... }
    
    But this kinda feeds back into the "why avoid exceptions when they're 
handled properly" discussion.


---
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