Skip to content

Bug: redundant GremlinServers will be opened when use cluster #19

@vayneYang

Description

@vayneYang

Hello! I found a bug in driver/cluster.py, which happend when using coroutines to send requests to gremlin-server. The impact is that redundant GremlinServers and its hosts will be established.

    async def get_connection(self, hostname=None):
        """
        **coroutine** Get connection from next available host in a round robin
        fashion.

        :returns: :py:class:`Connection<aiogremlin.driver.connection.Connection>`
        """
        if not self._hosts:
            await self.establish_hosts()
        if hostname:
            try:
                host = self._hostmap[hostname]
            except KeyError:
                raise exception.ConfigError(
                    'Unknown host: {}'.format(hostname))
        else:
            host = self._hosts.popleft()
        conn = await host.get_connection()
        self._hosts.append(host) 
        return conn

When self._hosts.popleft(), the variable host could be empty, which lead to other coroutines found that not self._hosts is True and establish a new one. Moving self._hosts.append(host) ahead of conn = await host.get_connection() can fix it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions