hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject hadoop git commit: HDFS-10222. libhdfs++: Shutdown sockets to avoid 'Connection reset by peer'. Contributed by James Clampffer
Date Wed, 30 Mar 2016 19:34:19 GMT
Repository: hadoop
Updated Branches:
  refs/heads/HDFS-8707 ff138e891 -> c2e1e23d8


HDFS-10222. libhdfs++: Shutdown sockets to avoid 'Connection reset by peer'.  Contributed
by James Clampffer


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/c2e1e23d
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/c2e1e23d
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/c2e1e23d

Branch: refs/heads/HDFS-8707
Commit: c2e1e23d8ea9a6002c1aafe18f7e6e7e41bb3301
Parents: ff138e8
Author: James <jhc@apache.org>
Authored: Wed Mar 30 15:33:48 2016 -0400
Committer: James <jhc@apache.org>
Committed: Wed Mar 30 15:33:48 2016 -0400

----------------------------------------------------------------------
 .../lib/connection/datanodeconnection.cc        |  4 +--
 .../lib/connection/datanodeconnection.h         | 31 +++++++++++++++++++-
 2 files changed, 31 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/c2e1e23d/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/connection/datanodeconnection.cc
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/connection/datanodeconnection.cc
b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/connection/datanodeconnection.cc
index 19878ab..be36fce 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/connection/datanodeconnection.cc
+++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/connection/datanodeconnection.cc
@@ -55,9 +55,7 @@ void DataNodeConnectionImpl::Connect(
 }
 
 void DataNodeConnectionImpl::Cancel() {
-  // best to do a shutdown() first for portability
-  conn_->shutdown(asio::ip::tcp::socket::shutdown_both);
-  conn_->close();
+  conn_.reset();
 }
 
 

http://git-wip-us.apache.org/repos/asf/hadoop/blob/c2e1e23d/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/connection/datanodeconnection.h
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/connection/datanodeconnection.h
b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/connection/datanodeconnection.h
index 6cb7f4a..96f2659 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/connection/datanodeconnection.h
+++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/connection/datanodeconnection.h
@@ -22,9 +22,12 @@
 #include "common/async_stream.h"
 #include "ClientNamenodeProtocol.pb.h"
 #include "common/libhdfs_events_impl.h"
+#include "common/logging.h"
 
 #include "asio.hpp"
 
+#include <exception>
+
 namespace hdfs {
 
 class DataNodeConnection : public AsyncStream {
@@ -38,9 +41,35 @@ public:
 };
 
 
+struct SocketDeleter {
+  inline void operator()(asio::ip::tcp::socket *sock) {
+    if(sock->is_open()) {
+      /**
+       *  Even though we just checked that the socket is open it's possible
+       *  it isn't in a state where it can properly send or receive.  If that's
+       *  the case asio will turn the underlying error codes from shutdown()
+       *  and close() into unhelpfully named std::exceptions.  Due to the
+       *  relatively innocuous nature of most of these error codes it's better
+       *  to just catch, give a warning, and move on with life.
+       **/
+      try {
+        sock->shutdown(asio::ip::tcp::socket::shutdown_both);
+      } catch (const std::exception &e) {
+        LOG_WARN(kBlockReader, << "Error calling socket->shutdown");
+      }
+      try {
+        sock->close();
+      } catch (const std::exception &e) {
+        LOG_WARN(kBlockReader, << "Error calling socket->close");
+      }
+    }
+    delete sock;
+  }
+};
+
 class DataNodeConnectionImpl : public DataNodeConnection, public std::enable_shared_from_this<DataNodeConnectionImpl>{
 public:
-  std::unique_ptr<asio::ip::tcp::socket> conn_;
+  std::unique_ptr<asio::ip::tcp::socket, SocketDeleter> conn_;
   std::array<asio::ip::tcp::endpoint, 1> endpoints_;
   std::string uuid_;
   LibhdfsEvents *event_handlers_;


Mime
View raw message