Repository navigation
Description
The issue
I was putting together a retry policy using the Polly library and thought checking .IsTransient property on the NpgsqlException instance would be exactly what is required, but I was surprised that TimeoutException is not included on the list of "transient" exception types.
npgsql/src/Npgsql/NpgsqlException.cs
Lines 41 to 46 in 8bf4219
| /// <summary> | |
| /// Specifies whether the exception is considered transient, that is, whether retrying to operation could | |
| /// succeed (e.g. a network error). | |
| /// </summary> | |
| public virtual bool IsTransient => | |
| InnerException is IOException || InnerException is SocketException; |
Based on the description, a connection timeout sounds like exactly the sort of thing that could succeed if retried. It seems @roji agreed a while back. What are your thoughts on adding TimeoutException to the list of transient exception types, possibly only for connection timeouts? I know the command timeouts are kind of a a separate story.
I think this would mean a change in these two places along with possibly a constructor change?
https://github.com/npgsql/npgsql/blob/4c0720ae703b5ac292dac872a8b1d728f6700f25/src/Npgsql/NpgsqlConnector.cs#L676
https://github.com/npgsql/npgsql/blob/4c0720ae703b5ac292dac872a8b1d728f6700f25/src/Npgsql/NpgsqlConnector.cs#L739
Thank you for this great library.
Further technical details
Npgsql version: latest
PostgreSQL version: 10.6
Operating system: Windows 1909
Other details about my project setup: .NET Core 3.1
Activity
roji commentedon Jan 29, 2020
Seems right to me... Unless I'm missing something, there's no need to change any of the throw sites you linked to above, or any constructor - just adding TimeoutException to the list in IsTransient should do the trick. Do you want to submit a PR for this?
Command timeouts aren't raised as TimeoutException, but as SocketException with error code TimedOut (see this test). So whatever we decide to do here with TimeoutException shouldn't affect that.
Thanks for the kind words :) Always appreciated!
nycdotnet commentedon Jan 30, 2020
Will do
YohDeadfall commentedon Jan 30, 2020
Closed by #2816.