Skip to content

error in COPY_OUT leaves the connection in ACTIVE state #203

@dvarrazzo

Description

@dvarrazzo

In a test like this:

    cur = conn.cursor()
    with pytest.raises(ZeroDivisionError):
        with cur.copy("copy (select generate_series(1, 2)) to stdout") as copy:
            copy.read_row()
            1 / 0

the connection is left in state ACTIVE, so we cannot do anything anymore with it.

The libpq doesn't have a command to terminate the COPY_OUT, as it has for COPY_IN. What we can do is to try and cancel the query, then consume the dataset until finished.

From a few preliminary tests, the server may or may not have already transferred the whole dataset to the client. If that's the case, the connection is left IDLE, otherwise it is left INERROR, when the QueryCanceled kicks in.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions