Skip to content

IsTransient for TimeoutException #2814

Closed
Closed

Description

@nycdotnet

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.

/// <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

  1. roji commented on Jan 29, 2020

    @roji
    Member

    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?

    I know the command timeouts are kind of a a separate story.

    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.

    Thank you for this great library.

    Thanks for the kind words :) Always appreciated!

  2. nycdotnet commented on Jan 30, 2020

    @nycdotnet
    ContributorAuthor

    Will do

  3. added this to the 5.0 milestone on Jan 30, 2020
  4. YohDeadfall commented on Jan 30, 2020

    @YohDeadfall
    Contributor

    Closed by #2816.

  5. modified the milestones: 5.0, 4.1.3 on Jan 30, 2020
  6. added theissue type on Jun 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions