kafka-jira mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (KAFKA-4245) BlockingChannel#connect hides all exceptions
Date Sun, 25 Feb 2018 21:24:00 GMT

    [ https://issues.apache.org/jira/browse/KAFKA-4245?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16376248#comment-16376248
] 

ASF GitHub Bot commented on KAFKA-4245:
---------------------------------------

hachikuji closed pull request #1948: KAFKA-4245: Don't swallow IOExceptions
URL: https://github.com/apache/kafka/pull/1948
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/core/src/main/scala/kafka/network/BlockingChannel.scala b/core/src/main/scala/kafka/network/BlockingChannel.scala
index 5408e0d34c7..27cbe416fef 100644
--- a/core/src/main/scala/kafka/network/BlockingChannel.scala
+++ b/core/src/main/scala/kafka/network/BlockingChannel.scala
@@ -17,6 +17,7 @@
 
 package kafka.network
 
+import java.io.IOException
 import java.net.InetSocketAddress
 import java.nio.channels._
 
@@ -82,7 +83,9 @@ class BlockingChannel( val host: String,
                          connectTimeoutMs))
 
       } catch {
-        case e: Throwable => disconnect()
+        case e: Throwable =>
+          disconnect()
+          throw new IOException("Connecting to %s:%d failed".format(host, port), e)
       }
     }
   }
diff --git a/core/src/main/scala/kafka/server/KafkaServer.scala b/core/src/main/scala/kafka/server/KafkaServer.scala
index 4ba9b2adad0..c62ef7b4c5d 100755
--- a/core/src/main/scala/kafka/server/KafkaServer.scala
+++ b/core/src/main/scala/kafka/server/KafkaServer.scala
@@ -494,8 +494,14 @@ class KafkaServer(val config: KafkaConfig, time: Time = SystemTime, threadNamePr
                   BlockingChannel.UseDefaultBufferSize,
                   BlockingChannel.UseDefaultBufferSize,
                   config.controllerSocketTimeoutMs)
-                channel.connect()
-                prevController = broker
+                try {
+                  channel.connect()
+                  prevController = broker
+                } catch {
+                  case ioe: IOException =>
+                    warn(ioe)
+                    channel = null
+                }
               }
             case None => //ignore and try again
           }
diff --git a/core/src/test/scala/unit/kafka/network/BlockingChannelTest.scala b/core/src/test/scala/unit/kafka/network/BlockingChannelTest.scala
new file mode 100644
index 00000000000..64f320582c6
--- /dev/null
+++ b/core/src/test/scala/unit/kafka/network/BlockingChannelTest.scala
@@ -0,0 +1,42 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package unit.kafka.network;
+
+import java.io.IOException
+
+import kafka.network.BlockingChannel
+
+import org.junit.Assert._
+import org.junit._
+import org.scalatest.junit.JUnitSuite
+
+class BlockingChannelTest extends JUnitSuite {
+
+  @Test
+  def testConnectFailure() {
+    val channel = new BlockingChannel("localhost", -1 /* Connecting on this port will fail
*/, 1024, 1024, 1000)
+    try {
+      channel.connect()
+      fail("Connecting to an invalid port should fail")
+    } catch {
+      case ioe: IOException => // Expected
+    }
+    assertFalse(channel.isConnected)
+  }
+
+}


 

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


> BlockingChannel#connect hides all exceptions
> --------------------------------------------
>
>                 Key: KAFKA-4245
>                 URL: https://issues.apache.org/jira/browse/KAFKA-4245
>             Project: Kafka
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 0.8.2.0, 0.9.0.0, 0.10.0.0
>            Reporter: Gabriel Reid
>            Priority: Major
>
> BlockingChannel currently swallows all Throwables that occur within the connect method;
it appears that this behavior was introduced somewhat inadvertently by KAFKA-1041. 
> A BlockingChannel for which connect() failed will not give any indication to the caller
that connecting failed, but the first call to send() or receive() will simply throw a ClosedChannelException.
This behavior gives the impression that a connection was dropped after having successfully
been set up, and hides any information about what failed when the original connection was
set up.
> It appears that basically all uses of BlockingChannel are implemented with the expectation
that an exception will be thrown by connect() if there is an issue connecting. In short, it
would make a lot more sense (and make diagnosis of issues a lot easier) if exceptions from
within BlockingChannel.connect were thrown all the way up the stack.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message