Limit TimeSpan timeouts to Int32 MaxValue - #1321
Conversation
|
@WojciechNagorski @Rob-Hague Ready for review and merge. |
Rob-Hague
left a comment
There was a problem hiding this comment.
I'm not seeing what problem this solves. If an underlying API doesn't accept a certain range of TimeSpan, aren't we going to get an error either way? Isn't it better to let the API decide?
I'm not sure what you mean by "the API". But basically, the issue boils down to the fact that the timeouts are injested by SSH.NET's public methods as TimeSpans but then used internally for timeouts that int based. The goal is to bring validation to the outer edge of the public methods of SSH.NET to avoid OutOfRange exceptions that could come from the internals of SSH.NET. |
|
How to reproduce the error or how does it manifest itself? I don't know what's improved here either? Can you add a test that didn't work before but now works? |
|
@Rob-Hague @WojciechNagorski The latest version that's in develop gives me a ton of IDE0005 build errors: |
I'll take care of it. |
I meant, if we're forwarding the TimeSpan to a method on e.g. I guess I felt like I was missing some context or motivation for this change. But I think it's OK in principal
That sounds like VS weirdness. It's OK for me (although sometimes it feels like the IDE doesn't know what to do with so many analyzers) |
Generally speaking, it is considered good design that libraries validate and throw early in public API methods. As an example of this, you can take analyzer rule CA1062 for null checks. The original reason I looked into this was because of #14, which although at the surface may seem superfluous, is actually valid. |
I'm using Rider and dotnet build with SDK 8.0.200. So I don't think this has anything to do with VS. |
…n Int32 in milliseconds.
…onInfoTimeout # Conflicts: # src/Renci.SshNet/Abstractions/SocketAbstraction.cs # src/Renci.SshNet/BaseClient.cs # src/Renci.SshNet/Common/TimeSpanExtensions.cs # src/Renci.SshNet/ConnectionInfo.cs # src/Renci.SshNet/ForwardedPort.cs # src/Renci.SshNet/ForwardedPortDynamic.cs # src/Renci.SshNet/ForwardedPortLocal.cs # src/Renci.SshNet/ForwardedPortRemote.cs # src/Renci.SshNet/NetConfClient.cs # src/Renci.SshNet/ScpClient.cs # src/Renci.SshNet/Sftp/SftpFileStream.cs # src/Renci.SshNet/SftpClient.cs # src/Renci.SshNet/SshCommand.cs
I added |
|
@WojciechNagorski @Rob-Hague Ready for final review and merge. |

Added guard clauses to various timeouts to ensure they don't exceed an Int32 in milliseconds.
Resolves #14.