0

We are using Npgsql to access a Postgres database. We recently upgrade Npgsql from 7.0.4 to 8.0.1 and since then we are experiencing irregular problems when calling stored procedures that take arrays of composite user defined types as parameters. We're running .NET 8.

The size of the array parameter varies from tens to hundreds, even more than a thousand of rows. However, the error occurrs irregularly to all sizes of parameter inputs. On the other hand, a failed call may succeed with the exact same input data when retried. Also, the majority of the cases succeed, also when the input size is really large.

I would appreciate any insights on this matter.

The exact error is:

System.InvalidOperationException: Buffer requirements for format not respected, expected no IO to be required.
   at Npgsql.Internal.PgConverter.ThrowIORequired()
   at Npgsql.Internal.Composites.CompositeFieldInfo`1.Write(Boolean async, PgConverter converter, PgWriter writer, Object instance, CancellationToken cancellationToken)
   at Npgsql.Internal.Converters.CompositeConverter`1.Write(Boolean async, PgWriter writer, T value, CancellationToken cancellationToken)
   at Npgsql.Internal.Converters.PgArrayConverter.Write(Boolean async, PgWriter writer, Object values, CancellationToken cancellationToken)
   at Npgsql.NpgsqlParameter.Write(Boolean async, PgWriter writer, CancellationToken cancellationToken)
   at Npgsql.Internal.NpgsqlConnector.WriteBind(List`1 parameters, String portal, Byte[] asciiName, Boolean allResultTypesAreUnknown, Boolean[] unknownResultTypeList, Boolean async, CancellationToken cancellationToken)
   at Npgsql.NpgsqlCommand.<Write>g__WriteExecute|100_0(NpgsqlConnector connector, Boolean async, Boolean flush, CancellationToken cancellationToken)
   at Npgsql.NpgsqlCommand.ExecuteReader(Boolean async, CommandBehavior behavior, CancellationToken cancellationToken)
   at Npgsql.NpgsqlCommand.ExecuteReader(Boolean async, CommandBehavior behavior, CancellationToken cancellationToken)
   at Npgsql.NpgsqlCommand.ExecuteNonQuery(Boolean async, CancellationToken cancellationToken)
   at [OUR OWN REPOSITORY CODE]

The Npgsql migration guide states that List-typed Npgsql parameters should be defined with the generic NpgsqlParameter. When the problems started we did not use the NpgsqlParameter type for list parameters, but we now have changed one of the most frequently failing calls to use this type, and we are still experiencing the error.

I have not yet tried increasing the buffer size in the Npgsql connection string, but I am not sure this is the right solution issue since problems also occur with small parameter sizes.

2
  • Can you please try the latest Npgsql patch daily build, and see if the issue stil reproduces there? We've done various buffering-related fixes there so it may be covered. If not, can you please open an issue on github.com/npgsql/npgsql, ideally with some sort of repro? Commented Jan 24, 2024 at 12:12
  • We finally ended up yesterday downgrading the Npgsql version back to 7.0.4 (while keeping .NET 8) since we were experiencing an unacceptable error rate. Unfortunately these exceptions have been occurring only in our production environment and I cannot test out the daily build there, but I thank you very much for your help and concern @ShayRojansky. Commented Jan 25, 2024 at 11:02

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.