Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix panic when logger or dialer is not set in canal config #743

Merged
merged 1 commit into from
Nov 28, 2022

Conversation

fungaren
Copy link
Contributor

If we do not use canal.NewDefaultConfig(), then the client will crash:

When Logger is nil

[2022/11/26 19:48:41] [info] binlogsyncer.go:156 create BinlogSyncer with config {999 mysql 10.43.173.151 3306 root    false false <nil> false UTC false 0 0s 0s 0 false false 0 <nil> 0xc00011b320}
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x5d1a45]

goroutine 1 [running]:
github.com/siddontang/go-log/log.(*Logger).Output(0x6bc30e?, 0xd?, 0x0?, {0xc00011ca40?, 0x0?})
        /home/fang/go/pkg/mod/github.com/siddontang/[email protected]/log/logger.go:137 +0x45
github.com/siddontang/go-log/log.(*Logger).Infof(0x0?, {0x6bc30e?, 0x0?}, {0x0?, 0xc000147f50?, 0x645db8?})
        /home/fang/go/pkg/mod/github.com/siddontang/[email protected]/log/logger.go:280 +0x51
github.com/go-mysql-org/go-mysql/canal.(*Canal).Close(0xc000288000)
        /home/fang/go/pkg/mod/github.com/go-mysql-org/[email protected]/canal/canal.go:240 +0x57
main.main()
        /home/fang/codes/panic-proof/main.go:33 +0x65
exit status 2

When Dialer is nil

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x5e97a5]

goroutine 1 [running]:
github.com/go-mysql-org/go-mysql/client.ConnectWithDialer({0x7955f0, 0xc0000672c0}, {0x0, 0x0}, {0x6ec54c, 0x12}, {0x6e591f, 0x4}, {0x6f3c3f, 0x20}, ...)
        /home/fang/codes/go-mysql/client/conn.go:84 +0xe5
github.com/go-mysql-org/go-mysql/canal.(*Canal).connect(0xc000256000, {0xc000123e38, 0x0, 0x0})
        /home/fang/codes/go-mysql/canal/canal.go:476 +0x111
github.com/go-mysql-org/go-mysql/canal.(*Canal).Execute(0xc000256000, {0x6f9320, 0x2b}, {0x0, 0x0, 0x0})
        /home/fang/codes/go-mysql/canal/canal.go:494 +0x27b
github.com/go-mysql-org/go-mysql/canal.(*Canal).checkBinlogRowFormat(0xc000256000?)
        /home/fang/codes/go-mysql/canal/canal.go:420 +0x30
github.com/go-mysql-org/go-mysql/canal.NewCanal(0xc0001e2ea0)
        /home/fang/codes/go-mysql/canal/canal.go:93 +0x318
main.main()
        /home/fang/codes/panic-proof/main.go:30 +0x58
exit status 2

To verify this:

package main

import (
	"github.com/go-mysql-org/go-mysql/canal"
	"github.com/go-mysql-org/go-mysql/mysql"
)

func main() {
	conf := canal.Config{
		ServerID: 999,
		Flavor:   mysql.MySQLFlavor,
		Addr:     "127.0.0.1:3306",
		User:     "root",
		Password: "password",
		Logger:   nil, // will panic if nil
		Dialer:   nil, // too.
	}
	c, err := canal.NewCanal(&conf)
	if err != nil {
		panic(err)
	}
	c.Close()
}

@lance6716 lance6716 merged commit 0999529 into go-mysql-org:master Nov 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants