8000 Introduce timeouts on sockets by ethomson · Pull Request #6535 · libgit2/libgit2 · GitHub
[go: up one dir, main page]

Skip to content

Introduce timeouts on sockets #6535

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? 8000 Sign in to your account

Merged
merged 12 commits into from
May 13, 2023
Merged

Introduce timeouts on sockets #6535

merged 12 commits into from
May 13, 2023

Conversation

ethomson
Copy link
Member

Make socket I/O non-blocking and add optional timeouts.

Users may now set GIT_OPT_SET_SERVER_CONNECT_TIMEOUT to set a shorter connection timeout. (The connect timeout cannot be longer than the operating system default.) Users may also now configure the socket read and write timeouts with GIT_OPT_SET_SERVER_TIMEOUT.

By default, connects still timeout based on the operating system defaults (typically 75 seconds) and socket read and writes block.

Add a test against our custom testing git server that ensures that we can timeout reads against a slow server.

@ethomson
Copy link
Member Author

Note: this is stacked on #6533.

@ethomson ethomson force-pushed the ethomson/timeouts branch 2 times, most recently from 854fd28 to a29e2c5 Compare March 21, 2023 16:05
@ASSIAPLI
Copy link

Espero que compreenda meu dialeto, vou analisar e ver como está .

@ethomson ethomson force-pushed the ethomson/timeouts branch 4 times, most recently from cc65b2a to 3676211 Compare May 13, 2023 13:18
ethomson added 12 commits May 13, 2023 16:42
`git__timer` is now `git_time_monotonic`, and returns milliseconds
since an arbitrary epoch.

Using a floating point to store the number of seconds elapsed was
clever, as it better supports the wide range of precision from the
different monotonic clocks of different systems. But we're a version
control system, not a real-time clock.

Milliseconds is a good enough precision for our work _and_ it's the
units that system calls like `poll` take and that our users interact
with.

Make `git_time_monotonic` return the monotonically increasing number
of milliseconds "ticked" since some arbitrary epoch.
We lose some error information from the read / write callbacks to
stransport. Store our own error value in the object so that we can
ensure that we rely upon it.
The `gitno` buffer interface is another layer on top of socket reads.
Abstract it a bit into a "static string" that has `git_str` like
semantics but without heap allocation which moves the actual reading
logic into the socket / stream code, and allows for easier future usage
of a static / stack-allocated `git_str`-like interface.
v0.6.0 of poxygit add support for throttling connections to test
timeouts and low-bandwidth situations.
Make socket I/O non-blocking and add optional timeouts.

Users may now set `GIT_OPT_SET_SERVER_CONNECT_TIMEOUT` to set a shorter
connection timeout. (The connect timeout cannot be longer than the
operating system default.) Users may also now configure the socket read
and write timeouts with `GIT_OPT_SET_SERVER_TIMEOUT`.

By default, connects still timeout based on the operating system
defaults (typically 75 seconds) and socket read and writes block.

Add a test against our custom testing git server that ensures that we
can timeout reads against a slow server.
Not all systems have poll(2); emulate it with select(2).
`check_symbol_exists` is superior to `check_function_exists`; use it
consistently in our cmake configuration
@ethomson ethomson force-pushed the ethomson/timeouts branch from 98b353e to 8f695c8 Compare May 13, 2023 15:42
@ethomson ethomson merged commit 9d41a3f into main May 13, 2023
@ethomson ethomson deleted the ethomson/timeouts branch July 15, 2023 14:33
@mascguy

This comment was marked as outdated.

@mascguy

This comment was marked as outdated.

@mascguy
Copy link
Contributor
mascguy commented Jul 20, 2023

Folks, I'm the maintainer of this lib for the MacPorts project. And one quick observation: The use of macOS constant errSSLNetworkTimeout in file src/libgit2/streams/stransport.c, now causes build failures for macOS 10.8 thru 10.12. (As that constant is only available in 10.13+.)
I'm happy to write up a formal issue. But just wanted to give you folks a proactive heads-up, to start the discussion on what the best approach to fixing this is.
Thoughts...?

Oh, and we're tracking this issue via ticket:

67774 - libgit2-devel @1.7.0: builds fail for 10.8 thru 10.12: use of undeclared identifier 'errSSLNetworkTimeout'

The simplest and least fragile option for us, would be to simply disable use of SecurityFramework for 10.12 and earlier. That's presently being done automatically for 10.7 and earlier, via checks in CMake file cmake/SelectHTTPSBackend.cmake. Though it doesn't look (?) like there's a formal option to easily force that. (Would be easy enough to patch said file to add one, but we'd prefer to collaborate with you folks on that.)

@ethomson
Copy link
Member Author

The simplest and least fragile option for us, would be to simply disable use of SecurityFramework for 10.12 and earlier.

I think it would be disappointing to use OpenSSL on macOS when there's a perfectly good SSL library that gets software updates with the system. I realize that MacPorts and Homebrew likely will do software updates, but somebody compiling libgit2 from source on 10.11 likely won't.

I think that we can likely just hardcode the value (like we do for ioErr)

@mascguy
Copy link
Contributor
mascguy commented Jul 20, 2023

The simplest and least fragile option for us, would be to simply disable use of SecurityFramework for 10.12 and earlier.

I think it would be disappointing to use OpenSSL on macOS when there's a perfectly good SSL library that gets software updates with the system. I realize that MacPorts and Homebrew likely will do software updates, but somebody compiling libgit2 from source on 10.11 likely won't.

I think that we can likely just hardcode the value (like we do for ioErr)

Sounds good, thank you for the quick response!

Is this something we should submit a PR for, or would you folks prefer to make the change?

@ethomson ethomson removed the feature label Jul 20, 2023
@ethomson
Copy link
Member Author

Is this something we should submit a PR for, or would you folks prefer to make the change?

You're very much welcome to. I won't have time to look at it until this weekend or early next week.

@mascguy
Copy link
Contributor
mascguy commented Jul 25, 2023

Is this something we should submit a PR for, or would you folks prefer to make the change?

You're very much welcome to. I won't have time to look at it until this weekend or early next week.

Done, thanks again for your help and quick response Edward!

PR 6610 - stransport: macOS: replace errSSLNetworkTimeout, with hard-coded value

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0