Skip to content

Fix behavior around failing to prepare statements - #2806

Merged
roji merged 1 commit into
devfrom
PrepareFailure
Jan 31, 2020
Merged

roji merged 1 commit into
devfrom
PrepareFailure

Conversation

@roji

@roji roji commented Jan 24, 2020 •

Copy link
Copy Markdown
Member

Fixes #2665
Fixes #2820

YohDeadfall
YohDeadfall previously approved these changes Jan 24, 2020
@roji
roji dismissed YohDeadfall’s stale review January 30, 2020 15:00

Changed PR considerably

@roji

roji commented Jan 30, 2020

Copy link
Copy Markdown
Member Author

@YohDeadfall I discovered another related bug (#2820), can you take another look at this?

Comment thread src/Npgsql/NpgsqlDataReader.cs Outdated

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.

This could be rewritten using if:

if (completedMsg.Code = BackendMessageCode.CompletedResponse ||
    completedMsg.Code = BackendMessageCode.EmptyQueryResponse)
{
    ProcessMessage(completedMsg);
    break;
}
else
    continue;

Not so important because saves only one line.

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.

The switch could actually be more efficient (possibly translated to a jump table by the compiler) :) Will leave as-is as you don't seem to mind.

Comment thread src/Npgsql/NpgsqlDataReader.cs Outdated

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.

if (msg.Code != BackendMessageCode.CompletedResponse &&
    msg.Code != BackendMessageCode.EmptyQueryResponse)
{
    throw Connector.UnexpectedMessageReceived(msg.Code);
}

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.

As above, I use switches for these cases mainly because of (theoretical) perf.

@YohDeadfall

Copy link
Copy Markdown
Contributor

Let's rebase it on top of the dev branch and use GitHub Actions.

@roji
roji merged commit afe2ac7 into dev Jan 31, 2020
@delete-merged-branch
delete-merged-branch Bot deleted the PrepareFailure branch January 31, 2020 16:51
using (var command = new NpgsqlCommand("INSERT INTO test_table (id) VALUES (1)", conn))
{
command.ExecuteNonQuery();
command.ExecuteNonQuery();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is there a reason you're executing twice here?

@cdaragorn

Copy link
Copy Markdown

We seem to be running into #2665 and are wondering if this is held up for some reason? We could really use this fix please.

@roji

roji commented Apr 21, 2021

Copy link
Copy Markdown
Member Author

@cdaragorn this fix was merged a long time ago - for 4.1.3. Can you please open a new issue with a minimal code sample for your problem?

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.

Exceptions in later batched statements aren't handled correctly in NpgsqlDataReader Failure during preparation leads to bad state

3 participants