{"record":{"id":"19196ca8c8d96546","repo":"alibaba/canal","slug":"expect-handshake-but-found-other-type","errorCode":null,"errorMessage":"expect handshake but found other type.","messagePattern":"expect handshake but found other type\\.","errorType":"exception","errorClass":"CanalClientException","httpStatus":null,"severity":"error","filePath":"admin/admin-web/src/main/java/com/alibaba/otter/canal/admin/connector/SimpleAdminConnector.java","lineNumber":77,"sourceCode":"    @Override\n    public void connect() throws ServiceException {\n        try {\n            if (connected) {\n                return;\n            }\n\n            channel = SocketChannel.open();\n            channel.socket().setSoTimeout(soTimeout);\n            channel.connect(address);\n            readableChannel = Channels.newChannel(channel.socket().getInputStream());\n            writableChannel = Channels.newChannel(channel.socket().getOutputStream());\n            Packet p = Packet.parseFrom(readNextPacket());\n            if (p.getVersion() != 1) {\n                throw new CanalClientException(\"unsupported version at this client.\");\n            }\n\n            if (p.getType() != PacketType.HANDSHAKE) {\n                throw new CanalClientException(\"expect handshake but found other type.\");\n            }\n\n            Handshake handshake = Handshake.parseFrom(p.getBody());\n            ByteString seed = handshake.getSeeds(); // seed for auth\n            String newPasswd = passwd;\n            if (passwd != null) {\n                // encode passwd\n                newPasswd = SecurityUtil.byte2HexStr(SecurityUtil.scramble411(passwd.getBytes(), seed.toByteArray()));\n            }\n\n            ClientAuth ca = ClientAuth.newBuilder()\n                .setUsername(user != null ? user : \"\")\n                .setPassword(ByteString.copyFromUtf8(newPasswd != null ? newPasswd : \"\"))\n                .setNetReadTimeout(idleTimeout)\n                .setNetWriteTimeout(idleTimeout)\n                .build();\n            writeWithHeader(Packet.newBuilder()\n                .setType(PacketType.CLIENTAUTHENTICATION)","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/alibaba/canal/blob/87be50e87686a3e8af08c368d0e1ffd1f59eb04a/admin/admin-web/src/main/java/com/alibaba/otter/canal/admin/connector/SimpleAdminConnector.java#L59-L95","documentation":"Thrown in doConnect() when the first packet's version is 1 but its type is not PacketType.HANDSHAKE. The admin connector expects the server to open with a handshake containing the auth seed; any other type means the connection state is wrong.","triggerScenarios":"The parsed Packet has type != HANDSHAKE on the first read. Occurs when connecting to a service that sends a different packet first, when the channel is mid-session from a previous connection, or when bytes are misaligned.","commonSituations":"Connecting to the wrong port (data/streaming port sends different packets); reconnecting to a channel not fully reset; partial bytes from a prior failed handshake left in the stream; protocol version skew.","solutions":["Verify the target is the admin port and not the streaming/data port.","Ensure a fresh SocketChannel is used (the code only connects if !connected; force a reconnect).","Align canal-admin and canal-server versions so the expected handshake packet is sent.","Check no proxy/LB is injecting bytes before the canal handshake."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    connector.connect();\n} catch (CanalClientException e) {\n    if (e.getMessage().contains(\"expect handshake\")) {\n        // likely wrong port or dirty channel; reconnect on a fresh channel\n    }\n    throw e;\n}","preventionTips":["Always connect on a freshly opened SocketChannel (the connector guards on !connected).","Confirm the port is the admin port, not the data/streaming port.","Keep admin and server versions aligned so the expected handshake is sent."],"tags":["network","protocol","handshake","canal-admin"],"backgroundTag":null,"analyzedSha":"87be50e87686a3e8af08c368d0e1ffd1f59eb04a","analyzedAt":"2026-08-14T04:30:11.918Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}