You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
NpgsqlConnection.WaitAsync(): Npgsql.NpgsqlException (0x80004005): Received backend message RowDescription while expecting ParseCompleteMessage. Please file a bug. #2506
I ran into this a few times while using a listener. I finally traced it back to a race condition with the cancellation token. Seems if a cancelled token gets sent to WaitAsync(), then the next command fails with this error. Here's some sample code (TableA is a non-existent). I tested with 4.0.7:
using (NpgsqlConnection connection = new NpgsqlConnection(connectionString))
{
connection.Open();
using (NpgsqlCommand command = new NpgsqlCommand("LISTEN TableA", connection))
{
command.ExecuteNonQuery();
}
using (CancellationTokenSource tokenSource = new CancellationTokenSource())
{
try
{
tokenSource.Cancel();
connection.WaitAsync(tokenSource.Token).Wait();
}
catch (AggregateException ex) when (ex.InnerExceptions.Any(x => (x is TaskCanceledException)))
{
}
}
using (NpgsqlCommand command = new NpgsqlCommand("SELECT NULL", connection))
{
command.ExecuteNonQuery();
}
}
I found that I can workaround this by locking the call to WaitAsync to prevent the cancel occurring before the async returns. So it appears everything is good to go if it makes it to the first await, It basically turns it into the following code, which works fine:
using (NpgsqlConnection connection = new NpgsqlConnection(connectionString))
{
connection.Open();
using (NpgsqlCommand command = new NpgsqlCommand("LISTEN TableA", connection))
{
command.ExecuteNonQuery();
}
using (CancellationTokenSource tokenSource = new CancellationTokenSource())
{
try
{
Task connectionWait = connection.WaitAsync(tokenSource.Token);
tokenSource.Cancel();
connectionWait.Wait();
}
catch (AggregateException ex) when (ex.InnerExceptions.Any(x => (x is TaskCanceledException)))
{
}
}
using (NpgsqlCommand command = new NpgsqlCommand("SELECT NULL", connection))
{
command.ExecuteNonQuery();
}
}
Activity
austindrenski commentedon Jun 30, 2019
@roji Looks like this was meant to close with #2507, but wasn't because f5bbc74 wasn't merged with our default branch (e.g.
dev).roji commentedon Jul 1, 2019
@austindrenski was keeping this open until #2443 is merged, which fixes this in dev.
roji commentedon Aug 27, 2019
This was actually merged into 4.0.8 as @austindrenski wrote above.