Skip to content

Stop swallowing exceptions in reader Dispose - #4677

Merged
roji merged 2 commits into
npgsql:mainfrom
roji:DisposeExceptions
Sep 25, 2022
Merged

roji merged 2 commits into
npgsql:mainfrom
roji:DisposeExceptions

Conversation

@roji

@roji roji commented Sep 25, 2022 •

Copy link
Copy Markdown
Member

And a fix to multiple exception handling with error barriers.

Closes #4377

@roji
roji requested a review from vonzshik as a code owner September 25, 2022 18:19
And a fix to multiple exception handling with error barriers.

Closes npgsql#4377
@roji
roji force-pushed the DisposeExceptions branch from 275f8df to 25d7b5c Compare September 25, 2022 18:21
Comment thread src/Npgsql/NpgsqlDataReader.cs Outdated
_commandLogger.LogError(e, "Exception caught while disposing a reader", Connector.Id);
if (e is not PostgresException)
// In the case of a PostgresException (or multiple ones, if we have error barriers), the reader's state has already been set
// to Disposed in Close above; otherwise, we need to set it here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vonzshik I see you added the condition to only set State to Disposed if the exceptions is not a PostgresException. I don't remember the context for that issue, but would it be problematic if we just always set it (either for any exception, or just in the finally)?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One potential issue here is multiplexing: after a reader is disposed, we return it to the connection, but it happens before we set the Disposed state here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I remember now. Updated the comment to make this clear.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, there is also CommandBehavior.CloseConnection, but the idea is the same.

@roji
roji force-pushed the DisposeExceptions branch from 3c15b1b to 50305db Compare September 25, 2022 19:11
@roji
roji merged commit cc70a3b into npgsql:main Sep 25, 2022
@roji
roji deleted the DisposeExceptions branch September 25, 2022 21:38
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 this pull request may close these issues.

ExecuteReader.Dispose should not swallow exceptions

2 participants