环境信息
canal 1.1.2 mysql 5.6
问题描述
启动canal连接本地的mysql,启动的时候会报错连接不上mysql
2018-12-11 17:55:47.455 [destination = example , address = /127.0.0.1:3306 , EventParser] ERROR c.a.o.c.p.inbound.mysql.rds.RdsBinlogEventParserProxy - dump address /127.0.0.1:3306 has an error, retrying. caused by com.alibaba.otter.canal.parse.exception.CanalParseException: java.io.IOException: connect /127.0.0.1:3306 failure Caused by: java.io.IOException: connect /127.0.0.1:3306 failure at com.alibaba.otter.canal.parse.driver.mysql.MysqlConnector.connect(MysqlConnector.java:77) ~[canal.parse.driver-1.1.2.jar:na] at com.alibaba.otter.canal.parse.inbound.mysql.MysqlConnection.connect(MysqlConnection.java:88) ~[canal.parse-1.1.2.jar:na] at com.alibaba.otter.canal.parse.inbound.mysql.MysqlEventParser.preDump(MysqlEventParser.java:86) ~[canal.parse-1.1.2.jar:na] at com.alibaba.otter.canal.parse.inbound.AbstractEventParser$3.run(AbstractEventParser.java:175) ~[canal.parse-1.1.2.jar:na] at java.lang.Thread.run(Thread.java:748) [na:1.8.0_161] Caused by: java.net.SocketException: Socket closed at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:118) ~[na:1.8.0_161] at java.net.SocketOutputStream.write(SocketOutputStream.java:143) ~[na:1.8.0_161] at com.alibaba.otter.canal.parse.driver.mysql.socket.BioSocketChannel.write(BioSocketChannel.java:36) ~[canal.parse.driver-1.1.2.jar:na] at com.alibaba.otter.canal.parse.driver.mysql.utils.PacketManager.writePkg(PacketManager.java:31) ~[canal.parse.driver-1.1.2.jar:na] at com.alibaba.otter.canal.parse.driver.mysql.MysqlConnector.negotiate(MysqlConnector.java:186) ~[canal.parse.driver-1.1.2.jar:na] at com.alibaba.otter.canal.parse.driver.mysql.MysqlConnector.connect(MysqlConnector.java:74) ~[canal.parse.driver-1.1.2.jar:na] ... 4 common frames omitted 2018-12-11 17:55:47.458 [destination = example , address = /127.0.0.1:3306 , EventParser] ERROR com.alibaba.otter.canal.common.alarm.LogAlarmHandler - destination:example[com.alibaba.otter.canal.parse.exception.CanalParseException: java.io.IOException: connect /127.0.0.1:3306 failure Caused by: java.io.IOException: connect /127.0.0.1:3306 failure at com.alibaba.otter.canal.parse.driver.mysql.MysqlConnector.connect(MysqlConnector.java:77) at com.alibaba.otter.canal.parse.inbound.mysql.MysqlConnection.connect(MysqlConnection.java:88) at com.alibaba.otter.canal.parse.inbound.mysql.MysqlEventParser.preDump(MysqlEventParser.java:86) at com.alibaba.otter.canal.parse.inbound.AbstractEventParser$3.run(AbstractEventParser.java:175) at java.lang.Thread.run(Thread.java:748) Caused by: java.net.SocketException: Socket closed at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:118) at java.net.SocketOutputStream.write(SocketOutputStream.java:143) at com.alibaba.otter.canal.parse.driver.mysql.socket.BioSocketChannel.write(BioSocketChannel.java:36) at com.alibaba.otter.canal.parse.driver.mysql.utils.PacketManager.writePkg(PacketManager.java:31) at com.alibaba.otter.canal.parse.driver.mysql.MysqlConnector.negotiate(MysqlConnector.java:186) at com.alibaba.otter.canal.parse.driver.mysql.MysqlConnector.connect(MysqlConnector.java:74) ... 4 more
然后我在上面报错的地方打了个断点,居然又不报错了,启动完全正常
public void connect() throws IOException { if (connected.compareAndSet(false, true)) { try { channel = SocketChannelPool.open(address); logger.info("connect MysqlConnection to {}...", address); negotiate(channel); // 这里打个断点,代码执行到这里的时候按F9直接跳过,居然又不报错了 } catch (Exception e) { disconnect(); throw new IOException("connect " + this.address + " failure", e); } } else { logger.error("the channel can't be connected twice."); } }
看logs/example/example.log 提示如下,看是启动成功,但是没有任何原因就stop了,输出如下
2018-12-11 17:43:41.876 [destination = example , address = /127.0.0.1:3306 , EventParser] WARN c.a.o.c.p.inbound.mysql.rds.RdsBinlogEventParserProxy - ---> begin to find start position, it will be long time for reset or first position 2018-12-11 17:43:41.876 [destination = example , address = /127.0.0.1:3306 , EventParser] WARN c.a.o.c.p.inbound.mysql.rds.RdsBinlogEventParserProxy - prepare to find start position just show master status 2018-12-11 17:43:41.889 [destination = example , address = /127.0.0.1:3306 , EventParser] WARN c.a.o.c.p.inbound.mysql.rds.RdsBinlogEventParserProxy - ---> find start position successfully, EntryPosition[included=false,journalName=mysql-bin.000004,position=1613,serverId=,gtid=,timestamp=] cost : 2ms , the next step is binlog dump 2018-12-11 17:43:51.204 [canal-instance-scan-0] INFO c.a.otter.canal.instance.core.AbstractCanalInstance - stop successful.... 不明真相,是不支持连接非rds 的 mysql 吗??
Steps to reproduce Expected behaviour Actual behaviour @362228416 Author 362228416 commented on Dec 11, 2018 打了断点,发现timer为null
protected void startHeartBeat(ErosaConnection connection) { lastEntryTime = 0L; // 初始化 if (timer == null) {// lazy初始化一下 String name = String.format("destination = %s , address = %s , HeartBeatTimeTask", destination, runningInfo == null ? null : runningInfo.getAddress().toString()); synchronized (AbstractEventParser.class) { // synchronized (MysqlEventParser.class) { // why use MysqlEventParser.class, u know, MysqlEventParser is // the child class 4 AbstractEventParser, // do this is ... if (timer == null) { timer = new Timer(name, true); } } }
if (heartBeatTimerTask == null) {// fixed issue #56,避免重复创建heartbeat线程
heartBeatTimerTask = buildHeartBeatTimeTask(connection);
Integer interval = detectingIntervalInSeconds;
// 这里的timer为null,报错了
timer.schedule(heartBeatTimerTask, interval * 1000L, interval * 1000L);
logger.info("start heart beat.... ");
}
}
@agapple Member agapple commented on Dec 11, 2018 使用独立软件模式测试一下
@362228416 Author 362228416 commented on Dec 11, 2018 独立版本可以,那我这个是什么情况
@agapple Member agapple commented on Mar 23, 2019 如果是IDE里启动, 直接debug看一下为啥会null吧
@agapple agapple closed this as completed on Mar 23, 2019 to join this conversation on GitHub. Already have an account? Sign in to comment Assignees No one assigned Labels None yet Projects None yet Milestone No milestone Development No branches or pull requests
2 participants @agapple @362228416
看logs/example/example.log 提示如下,看是启动成功,但是没有任何原因就stop了,输出如下
2018-12-11 17:43:41.876 [destination = example , address = /127.0.0.1:3306 , EventParser] WARN c.a.o.c.p.inbound.mysql.rds.RdsBinlogEventParserProxy - ---> begin to find start position, it will be long time for reset or first position 2018-12-11 17:43:41.876 [destination = example , address = /127.0.0.1:3306 , EventParser] WARN c.a.o.c.p.inbound.mysql.rds.RdsBinlogEventParserProxy - prepare to find start position just show master status 2018-12-11 17:43:41.889 [destination = example , address = /127.0.0.1:3306 , EventParser] WARN c.a.o.c.p.inbound.mysql.rds.RdsBinlogEventParserProxy - ---> find start position successfully, EntryPosition[included=false,journalName=mysql-bin.000004,position=1613,serverId=,gtid=,timestamp=] cost : 2ms , the next step is binlog dump 2018-12-11 17:43:51.204 [canal-instance-scan-0] INFO c.a.otter.canal.instance.core.AbstractCanalInstance - stop successful....
不明真相,是不支持连接非rds 的 mysql 吗??
原提问者GitHub用户362228416
使用独立软件模式测试一下,如果是IDE里启动, 直接debug看一下为啥会null吧。
原回答者GitHub用户agapple
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。