Skip to content

need check error when read from mysql #464

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

Closed
zeast opened this issue Jun 23, 2016 · 2 comments · Fixed by #473
Closed

need check error when read from mysql #464

zeast opened this issue Jun 23, 2016 · 2 comments · Fixed by #473

Comments

@zeast
Copy link

zeast commented Jun 23, 2016

Issue description

The function readUntilEOF of struct mysqlConn did not check if data[0] is 0xff.
If I exec a lock command like ' select id from foo for update ', mysql maybe return a timeout error. Without check, program will wait for read forever.

Example code

// Reads Packets until EOF-Packet or an Error appears. Returns count of Packets read
func (mc *mysqlConn) readUntilEOF() error {
    for {
        data, err := mc.readPacket()
        if err != nil {
            return err
        }

        //check if a error packet
        if data[0] == iERR {
            //read the error code and error message
            //https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
        }

        // No Err and no EOF Packet
        if err == nil && data[0] != iEOF {
            continue
        }
        if err == nil && data[0] == iEOF && len(data) == 5 {
            mc.status = readStatus(data[3:])
        }

        return nil // Err or EOF
    }
}

Configuration

go version go1.6.2 darwin/amd64

mysql Ver 14.14 Distrib 5.7.12, for osx10.11 (x86_64) using EditLine wrapper

OS X EI Capitan 10.11.5

@qbig
Copy link

qbig commented Jul 5, 2016

I encounter a very similar issue. In my case, mc.buf was corrupted. So in

func (rows *mysqlRows) Close() error {
    mc := rows.mc
    if mc == nil {
        return nil
    }
    if mc.netConn == nil {
        return ErrInvalidConn
    }

    // Remove unread packets from stream
    err := mc.readUntilEOF()
    rows.mc = nil
    return err
}

which calls readUntilEOF()

mc.readPacket(), pktLen would actually come from garbage and return a huge number. And as a result it would wait forever.

go1.6.2 darwin/amd64
OS X EI Capitan 10.11.5

@qbig
Copy link

qbig commented Aug 2, 2016

related to golang/go#8874 ?

methane added a commit to methane/mysql that referenced this issue Aug 2, 2016
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 a pull request may close this issue.

2 participants