go-mysql-org / go-mysql

a powerful mysql toolset with Go
MIT License
4.52k stars 967 forks source link

[Warning] Aborted connection 52412 to db: 'unconnected' user: 'boss' host: '' (Got an error reading communication packets) #847

Closed 601630051 closed 5 months ago

601630051 commented 5 months ago
package main

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

type MyEventHandler struct {
    canal.DummyEventHandler
}

func (h *MyEventHandler) OnRow(e *canal.RowsEvent) error {
    log.Infof("%s %v\n", e.Action, e.Rows)
    return nil
}

func (h *MyEventHandler) String() string {
    return "MyEventHandler"
}
var cc *canal.Canal
func main() {
    cfg := canal.NewDefaultConfig()
    cfg.Addr = "127.0.0.1:3306"
    cfg.User = "root"
    // We only care table canal_test in test db
    cfg.Dump.TableDB = "test"
    cfg.Dump.Tables = []string{"canal_test"}

    cc, err := canal.NewCanal(cfg)
    if err != nil {
        log.Fatal(err)
    }

    // Register a handler to handle RowsEvent
    cc.SetEventHandler(&MyEventHandler{})
        go Close()
    // Start canal
    cc.Run()
}

func Close() {
    time.Sleep(time.Second * 10)
    cc.Close()
    fmt.Println("close")
}

When the program ends manually. mysql service error:

[Warning] Aborted connection 52412 to db: 'unconnected' user: 'boss' host: '' (Got an error reading communication packets)

dveeden commented 5 months ago

What is the go-mysql and server version and type (MySQL/MariaDB/TiDB/etc) ? Any chance you could add a network trace (tcpdump/dumpcap)?

dveeden commented 5 months ago

I've updated the issue description to format the Go code correctly. Hope that's ok.

dveeden commented 5 months ago

This could be related to https://github.com/go-mysql-org/go-mysql/issues/374

601630051 commented 5 months ago

MariaDB

My MariaDB

dveeden commented 5 months ago

MariaDB

My MariaDB

What version?

601630051 commented 5 months ago

MariaDB

My MariaDB

What version?

10.4.8-MariaDB-log

601630051 commented 5 months ago

This could be related to #374 go-mysql-org\go-mysql@v1.7.0\client\conn.go

func (c *Conn) Close() error { c.writeCommand(COM_QUIT) return c.Conn.Close() } The problem has been resolved!!!!!