Coder Social home page Coder Social logo

Comments (9)

siddontang avatar siddontang commented on May 30, 2024

The code in close sets a 100ms timeout here

if b.c != nil {
        b.c.SetReadDeadline(time.Now().Add(100 * time.Millisecond))
    }

how about using b.c.Close() directly?

from go-mysql.

lxohi avatar lxohi commented on May 30, 2024
        if b.c != nil {
                b.c.SetReadDeadline(time.Now().Add(100 * time.Millisecond))
        }
        b.c.Close()

I tried to add b.c.Close() here in replication/binlogsyncer.go.
After adding this line, the process exit successfully.

from go-mysql.

siddontang avatar siddontang commented on May 30, 2024

Em, SetReadDeadline will have no effect if reading some data in 100ms and then be cleared. Maybe Close is right here.
can you send me a PR to fix this?

from go-mysql.

lxohi avatar lxohi commented on May 30, 2024

Sure, but I found another problem when verifying the fix code.
Even if I called b.c.Close() here, there is still a case that blocking on b.wg.Wait().
Because BinlogSyncer.parseEvent is sending BinlogEvent to a buffered channel(s.ch), so onStream method may be blocking on it.

from go-mysql.

siddontang avatar siddontang commented on May 30, 2024

How about SetReadDeadline(0)?

from go-mysql.

lxohi avatar lxohi commented on May 30, 2024

The point is BinlogSyncer.parseEvent thread may be already blocked on s.ch before BinlogSyncer.Close() was called.
As long as BinlogSyncer.Close() waiting on b.wg.Wait(), no matter how to close the TCP connection, onStream method on the other thread will not decrease the WaitGroup.

from go-mysql.

siddontang avatar siddontang commented on May 30, 2024

@andwxh , can above PR fix this problem?

from go-mysql.

lxohi avatar lxohi commented on May 30, 2024

Yeah! This time its completely fixed. Thank you.

from go-mysql.

lxohi avatar lxohi commented on May 30, 2024

I wondered is it a good practice to use two variables (wg & stopCh) in Close(), in order to ensure onStream thread stopped. But it works now.

from go-mysql.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.