Github user galen-pivotal commented on a diff in the pull request: https://github.com/apache/geode/pull/716#discussion_r134021675 --- Diff: geode-core/src/main/java/org/apache/geode/distributed/internal/tcpserver/TcpServer.java --- @@ -334,107 +351,109 @@ protected void run() { * fix for bug 33711 - client requests are spun off to another thread for processing. Requests are * synchronized in processGossip. */ - private void processRequest(final Socket sock) { + private void processRequest(final Socket socket) { executor.execute(() -> { long startTime = DistributionStats.getStatTime(); DataInputStream input = null; Object request, response; try { - sock.setSoTimeout(READ_TIMEOUT); - getSocketCreator().configureServerSSLSocket(sock); + socket.setSoTimeout(READ_TIMEOUT); + getSocketCreator().configureServerSSLSocket(socket); try { - input = new DataInputStream(sock.getInputStream()); + input = new DataInputStream(socket.getInputStream()); } catch (StreamCorruptedException e) { // Some garbage can be left on the socket stream // if a peer disappears at exactly the wrong moment. log.debug("Discarding illegal request from " - + (sock.getInetAddress().getHostAddress() + ":" + sock.getPort()), e); + + (socket.getInetAddress().getHostAddress() + ":" + socket.getPort()), e); return; } - int gossipVersion = readGossipVersion(sock, input); + int gossipVersion = readGossipVersion(socket, input); short versionOrdinal; - if (gossipVersion <= getCurrentGossipVersion() - && GOSSIP_TO_GEMFIRE_VERSION_MAP.containsKey(gossipVersion)) { - // Create a versioned stream to remember sender's GemFire version - versionOrdinal = (short) GOSSIP_TO_GEMFIRE_VERSION_MAP.get(gossipVersion); - } else { - // Close the socket. We can not accept requests from a newer version - try { - sock.getOutputStream().write("unknown protocol version".getBytes()); - sock.getOutputStream().flush(); - } catch (IOException e) { - log.debug( - "exception in sending reply to process using unknown protocol " + gossipVersion, e); + if (gossipVersion == NON_GOSSIP_REQUEST_VERSION) { + if (input.readUnsignedByte() == PROTOBUF_CLIENT_SERVER_PROTOCOL + && Boolean.getBoolean("geode.feature-protobuf-protocol")) { + messageHandler.receiveMessage(input, socket.getOutputStream(), + new MessageExecutionContext(internalLocator)); + } else { + rejectUnknownProtocolConnection(socket, gossipVersion); } - sock.close(); - return; - } - if (Version.GFE_71.compareTo(versionOrdinal) <= 0) { - // Recent versions of TcpClient will send the version ordinal - versionOrdinal = input.readShort(); - } - - if (log.isDebugEnabled() && versionOrdinal != Version.CURRENT_ORDINAL) { - log.debug("Locator reading request from " + sock.getInetAddress() + " with version " - + Version.fromOrdinal(versionOrdinal, false)); - } - input = new VersionedDataInputStream(input, Version.fromOrdinal(versionOrdinal, false)); - request = DataSerializer.readObject(input); - if (log.isDebugEnabled()) { - log.debug("Locator received request " + request + " from " + sock.getInetAddress()); - } - if (request instanceof ShutdownRequest) { - shuttingDown = true; - // Don't call shutdown from within the worker thread, see java bug #6576792. - // Closing the socket will cause our acceptor thread to shutdown the executor - this.serverSocketPortAtClose = srv_sock.getLocalPort(); - srv_sock.close(); - response = new ShutdownResponse(); - } else if (request instanceof InfoRequest) { - response = handleInfoRequest(request); - } else if (request instanceof VersionRequest) { - response = handleVersionRequest(request); } else { - response = handler.processRequest(request); - } - - handler.endRequest(request, startTime); + if (gossipVersion <= getCurrentGossipVersion() --- End diff -- Also, we only early return in one rejection case; the end result is the same but it would be nice to be consistent.
--- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. ---