Skip to content
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

ReportRemoteError() changes can lead to PurgeConnection() being missed. #587

Closed
anarazel opened this issue Jun 8, 2016 · 4 comments · Fixed by #615
Closed

ReportRemoteError() changes can lead to PurgeConnection() being missed. #587

anarazel opened this issue Jun 8, 2016 · 4 comments · Fixed by #615
Assignees
Milestone

Comments

@anarazel
Copy link
Contributor

anarazel commented Jun 8, 2016

Previously calling code could do a PurgeConnection() after a command failed. But with the changed API that's not really possible anymore. As the result and connection needs to be passed to ReraiseRemoteError(), result/connection can't be cleared afterwards. Due to raised error it can't be cleared afterwards either.

That's problematic because at that stage not all data from the remote site might have been consumed, we might be in an incomplete transactional state, or various variations like that. For #578 I've temporarily hacked things together by putting


    if (errorLevel >= ERROR)
    {
        PurgeConnection(connection);
    }

just before the ereport()s in ReportRemoteError(), but ...

@jasonmp85
Copy link
Contributor

Good catch. I suggest we look at what postgres_fdw does for this (I believe it wraps its own throw in a try/catch in order to have a block where it can reliably clear things).

@anarazel
Copy link
Contributor Author

anarazel commented Jun 9, 2016

That's a possibility, yes. I'm actually kind of inclined to rather go the route of the PurgeConnection inside ReraiseRemoteError(). Not pretty, but a lot easier. Writing correct code around PG_TRY/CATCH isn't easy (cf. SETJMP(3)'s NOTES section).

@metdos
Copy link
Contributor

metdos commented Jun 10, 2016

We also need to clear PGresult in the error case, right?

@metdos metdos modified the milestone: 5.2 Release Jun 10, 2016
@anarazel
Copy link
Contributor Author

On 2016-06-10 07:16:30 -0700, Metin Döşlü wrote:

We also need to clear PGresult in the error case, right?

Closing a connection should take care of that:

static void
closePGconn(PGconn *conn)
{
...
    pqClearAsyncResult(conn);   /* deallocate result */
}
...

void
pqClearAsyncResult(PGconn *conn)
{
    if (conn->result)
        PQclear(conn->result);
    conn->result = NULL;
    if (conn->next_result)
        PQclear(conn->next_result);
    conn->next_result = NULL;
}

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.

4 participants