npgsql: Throw OperationCanceledException for cancellation instead of PostgresException

https://github.com/npgsql/npgsql/commit/610e319e8f11fe44144a19e6943d6c5 190eb8555

Should catch, but only invoke Connector.Break() and not throw the exception on an OperationCanceledException (which also catches TaskCanceledException)?

Npgsql.NpgsqlException: Exception while reading from stream --->
System.Threading.Tasks.TaskCanceledException: A task was canceled.
  --- End of inner exception stack trace ---
  at Npgsql.ReadBuffer+<EnsureAsync>c__async0.MoveNext () [0x00266] in
/home/mkj/rpm/BUILD/npgsql-3.1.2/src/Npgsql/GeneratedAsync.cs:1494

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 2
  • Comments: 19 (15 by maintainers)

Commits related to this issue

Most upvoted comments

After a long time with no reaction whatsoever from Microsoft, let’s change Npgsql to do the right thing for 3.3.

@KrzysztofBranicki sorry, I was missing the context of this issue when I wrote my previous comment - please ignore.

I do absolutely believe we should be throwing OperationCanceledException/TaskCanceledException, and will do my best to have that done for 5.0. The only reason it hasn’t been done yet has been priorities and too much work generally.

@roji I see the point in doing the same as SqlClient and also the point of being able to catch all exceptions as NpgsqlExceptions.

But a TaskCanceledException is not really an exception in the sense that it is unexpected, it is expected behavior when you cancel a token. So I would prefer to get a TaskCanceledException, instead of having to catch a NpgsqlException and check the InnerException. (Not sure how to do this in SqlClient, do they want people to match on the string).

I would prefer option 1.