Code Monkey home page Code Monkey logo

Comments (3)

haizaar avatar haizaar commented on July 22, 2024

You are right. However it looks like the issue is even deeper - if I call Pool.close() in the middle operation, the retry logic will reestablish the connection, so at the end Pool.close() does not do its jobs well.

I think the retry logic should not act if Pool.closed is true; and yes, Pool.close() should not empty connection sets .

Also I wonder whether public API should assert not self.closed before doing anything.

What do you think?

from momoko.

masknu avatar masknu commented on July 22, 2024

@haizaar , I agree with your concern. I tried a few changes in momoko to make it work right under any closing time, some changes like:

def connect(self):
    future = Future()
    assert self.conns.total <= self.size, "total should not greater than size"
    size = self.size - self.conns.total

    #add check here
    if 0 == size and self.conns.all_dead:

        def on_getconn(fut):
            try:
                conn = fut.result()
            except Exception as error:
                future.set_exc_info(sys.exc_info())
            else:
                future.set_result(self)
                self.putconn(conn)

        self.ioloop.add_future(self.getconn(), on_getconn)
        return future

    #change pending count here
    pending = [max(size-1, 0)]

    def on_connect(fut):
        if pending[0]:
            pending[0] -= 1
            return
        # all connection attempts are complete
        if self.conns.dead and self.raise_connect_errors:
            ecp = PartiallyConnectedError("%s connection(s) failed to connect" % len(self.conns.dead))
            future.set_exception(ecp)
        else:
            future.set_result(self)
        log.debug("All initial connection requests complete")

    #create connection use altered size
    for i in range(size):
        self.ioloop.add_future(self._new_connection(), on_connect)

    return future

After the changes we made, I prefer to use Pool.getconn at the beginning instead of Pool.conncet, It could make life simple, change connection.L316 in Pool.getconn to:

            if self.conns.total:
                self.ioloop.add_future(self._reanimate(), on_reanimate_done)
            else:
                #new db object, and haven't invoked connect(),start with one connection
                self.ioloop.add_future(self._new_connection(), on_reanimate_done)

from momoko.

haizaar avatar haizaar commented on July 22, 2024

Frankly I'm a bit swamped and hardly will get to work on it until middle next week. If you want to submit PRs with unittests for each of the issues, I'll be happy to review and merge them. Do you want to give it a shot?

from momoko.

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.