Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit TimeSpan timeouts to Int32 MaxValue #1321

Merged
merged 13 commits into from
Feb 20, 2024

Conversation

jscarle
Copy link
Contributor

@jscarle jscarle commented Feb 13, 2024

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

Resolves #14.

@jscarle jscarle force-pushed the feature/ConnectionInfoTimeout branch from 34e4285 to ead7bd0 Compare February 13, 2024 21:50
@jscarle jscarle force-pushed the feature/ConnectionInfoTimeout branch from ead7bd0 to 3ad2451 Compare February 13, 2024 21:57
@jscarle
Copy link
Contributor Author

jscarle commented Feb 16, 2024

@WojciechNagorski @Rob-Hague Ready for review and merge.

Copy link
Collaborator

@Rob-Hague Rob-Hague left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

src/Renci.SshNet/Common/TimeSpanExtensions.cs Outdated Show resolved Hide resolved
src/Renci.SshNet/Common/TimeSpanExtensions.cs Show resolved Hide resolved
@jscarle
Copy link
Contributor Author

jscarle commented Feb 16, 2024

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.

@WojciechNagorski
Copy link
Collaborator

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?

@jscarle
Copy link
Contributor Author

jscarle commented Feb 17, 2024

@Rob-Hague @WojciechNagorski The latest version that's in develop gives me a ton of IDE0005 build errors:

image

@jscarle
Copy link
Contributor Author

jscarle commented Feb 17, 2024

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?

I'll take care of it.

@Rob-Hague
Copy link
Collaborator

I'm not sure what you mean by "the API".

I meant, if we're forwarding the TimeSpan to a method on e.g. Socket or Monitor, then those methods will perform their own validation and throw if they don't accept a certain value, so there should be no need to try and presume what values are acceptable or not.

I guess I felt like I was missing some context or motivation for this change. But I think it's OK in principal

The latest version that's in develop gives me a ton of IDE0005 build errors

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)

@jscarle
Copy link
Contributor Author

jscarle commented Feb 17, 2024

I'm not sure what you mean by "the API".

I meant, if we're forwarding the TimeSpan to a method on e.g. Socket or Monitor, then those methods will perform their own validation and throw if they don't accept a certain value, so there should be no need to try and presume what values are acceptable or not.

I guess I felt like I was missing some context or motivation for this change. But I think it's OK in principal

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.

@jscarle
Copy link
Contributor Author

jscarle commented Feb 17, 2024

The latest version that's in develop gives me a ton of IDE0005 build errors

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)

I'm using Rider and dotnet build with SDK 8.0.200. So I don't think this has anything to do with VS.

…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
@jscarle
Copy link
Contributor Author

jscarle commented Feb 17, 2024

The latest version that's in develop gives me a ton of IDE0005 build errors

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)

I'm using Rider and dotnet build with SDK 8.0.200. So I don't think this has anything to do with VS.

I added IDE0005 to the .editorconfig.

@jscarle
Copy link
Contributor Author

jscarle commented Feb 17, 2024

@WojciechNagorski @Rob-Hague Ready for final review and merge.

@jscarle jscarle requested a review from Rob-Hague February 17, 2024 16:05
@jscarle
Copy link
Contributor Author

jscarle commented Feb 20, 2024

@WojciechNagorski I fixed the reference you mentioned. I must have been really tired, that slipped right past me.

Comment on lines +162 to +165

# IDE0005: Remove unnecessary using directives
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0005
dotnet_diagnostic.IDE0005.severity = suggestion
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you revert this? I think after restarting VS (or restarting your computer) everything should work.

This is the last message and then I will be able to merge this PR.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am seeing this locally as well, the errors look real. I think it could be related to upgrading the SDK but I have no idea why we haven't seen it before.

I am trying to fix it with dotnet format but not having much luck :-(

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wrong, I don't know what's going on.

Copy link
Collaborator

@WojciechNagorski WojciechNagorski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@WojciechNagorski WojciechNagorski merged commit 4b9c3bf into sshnet:develop Feb 20, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ConnectionInfo Timeout doesn't allow for Int64.MaxValue as designed
3 participants