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

Add compile-time flag to remove code for QUIC #2364

Merged

Conversation

syeopite
Copy link
Member

No description provided.

@syeopite syeopite closed this Aug 31, 2021
@syeopite syeopite reopened this Aug 31, 2021
@syeopite syeopite marked this pull request as draft August 31, 2021 21:52
@syeopite
Copy link
Member Author

Using Invidious without QUIC has some issues

@syeopite syeopite closed this Sep 1, 2021
@unixfox
Copy link
Member

unixfox commented Sep 1, 2021

Why this got closed? I know how to fix the issues.

@syeopite syeopite reopened this Sep 1, 2021
@syeopite syeopite force-pushed the disable-quic-via-compile-time-flag branch from 1c585d6 to a5344cf Compare September 28, 2021 22:10
@syeopite
Copy link
Member Author

syeopite commented Sep 28, 2021

There we go, that should fix the gzip issues. However, in order to make Invidious fully functional without lsquic, we're going to need to replace the few dozen usages of :authority with a HTTP/1.1 equivalent; otherwise, we can't support images. That's a bit out of scope for this PR though.

@syeopite syeopite marked this pull request as ready for review September 28, 2021 22:15
src/invidious/helpers/utils.cr Outdated Show resolved Hide resolved
conn = QUIC::Client.new(url)
else
DB::Pool(ConnectonClientType).new(initial_pool_size: 0, max_pool_size: capacity, max_idle_pool_size: capacity, checkout_timeout: timeout) do
conn = nil # Declare
Copy link
Member

Choose a reason for hiding this comment

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

This is not required

Copy link
Member Author

Choose a reason for hiding this comment

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

It is actually required. The disable_quic logic is considered a macro(?) so we can't actually access conn unless we declare it outside first. You can try to build Invidious without this yourself, but it'll just result in a compile time error.

Copy link
Member

Choose a reason for hiding this comment

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

Whaaaa, even the inline version doesn't work!
conn = {% unless flag?(:disable_quic) %} use_quic ? QUIC::Client.new(url) : {% end %} HTTP::Client.new(url)

This is definitely an upstream bug...

Copy link
Member

@SamantazFox SamantazFox Sep 29, 2021

Choose a reason for hiding this comment

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

That works, though:

conn = (
  {% unless flag?(:disable_quic) %}
    CONFIG.use_quic ? QUIC::Client.new(url) : HTTP::Client.new(url)
  {% else %}
    HTTP::Client.new(url)
  {% end %}
)

src/invidious/routes/login.cr Outdated Show resolved Hide resolved
src/invidious/routes/login.cr Show resolved Hide resolved
src/invidious/helpers/utils.cr Outdated Show resolved Hide resolved
@TheFrenchGhosty TheFrenchGhosty added ready blocked require something else first and removed ready labels Oct 3, 2021
@TheFrenchGhosty TheFrenchGhosty marked this pull request as draft October 3, 2021 17:16
@TheFrenchGhosty
Copy link
Member

Blocked by #2364 (comment)

@syeopite syeopite marked this pull request as ready for review October 8, 2021 15:00
@syeopite syeopite requested a review from a team as a code owner October 8, 2021 15:00
@syeopite
Copy link
Member Author

syeopite commented Oct 8, 2021

Blocked by #2364 (comment)

Should be fixed.

@syeopite syeopite added ready and removed blocked require something else first labels Oct 8, 2021
@syeopite
Copy link
Member Author

syeopite commented Oct 13, 2021

Running this PR causes the following to be outputted within the logs occasionally. Though, it doesn't seem to actually cause any noticeable effect.

Exception: SSL_connect: I/O error (OpenSSL::SSL::Error)
  from /usr/share/crystal/src/openssl/ssl/socket.cr:34:11 in 'initialize'
  from /usr/share/crystal/src/openssl/ssl/socket.cr:3:5 in 'new:context:sync_close:hostname'
  from src/invidious/helpers/crystal_class_overrides.cr:34:5 in 'io'
  from /usr/share/crystal/src/http/client.cr:664:5 in 'send_request'
  from /usr/share/crystal/src/http/client.cr:599:5 in 'exec_internal_single'
  from /usr/share/crystal/src/http/client.cr:586:5 in 'exec_internal'
  from /usr/share/crystal/src/http/client.cr:581:7 in 'exec'
  from /usr/share/crystal/src/http/client.cr:706:5 in 'exec'
  from /usr/share/crystal/src/http/client.cr:738:7 in 'exec'
  from /usr/share/crystal/src/http/client.cr:406:3 in 'head'
  from src/invidious.cr:1514:7 in '->'
  from /usr/share/crystal/src/primitives.cr:266:3 in '->'
  from src/invidious/helpers/handlers.cr:30:5 in 'process_request'
  from lib/kemal/src/kemal/route_handler.cr:17:7 in 'call'
  from /usr/share/crystal/src/http/server/handler.cr:28:7 in 'call_next'
  from lib/kemal/src/kemal/websocket_handler.cr:13:14 in 'call'
  from /usr/share/crystal/src/http/server/handler.cr:28:7 in 'call_next'
  from lib/kemal/src/kemal/filter_handler.cr:21:7 in 'call'
  from /usr/share/crystal/src/http/server/handler.cr:28:7 in 'call_next'
  from src/invidious/helpers/handlers.cr:212:5 in 'call'
  from /usr/share/crystal/src/http/server/handler.cr:28:7 in 'call_next'
  from src/invidious/helpers/handlers.cr:94:12 in 'call'
  from /usr/share/crystal/src/http/server/handler.cr:28:7 in 'call_next'
  from src/invidious/helpers/handlers.cr:145:12 in 'call'
  from /usr/share/crystal/src/http/server/handler.cr:28:7 in 'call_next'
  from src/invidious/helpers/handlers.cr:68:12 in 'call'
  from /usr/share/crystal/src/http/server/handler.cr:28:7 in 'call_next'
  from src/invidious/helpers/static_file_handler.cr:189:11 in 'call'
  from /usr/share/crystal/src/http/server/handler.cr:28:7 in 'call_next'
  from lib/kemal/src/kemal/exception_handler.cr:8:7 in 'call'
  from /usr/share/crystal/src/http/server/handler.cr:28:7 in 'call_next'
  from src/invidious/helpers/logger.cr:17:35 in 'call'
  from /usr/share/crystal/src/http/server/handler.cr:28:7 in 'call_next'
  from lib/kemal/src/kemal/init_handler.cr:12:7 in 'call'
  from /usr/share/crystal/src/http/server/request_processor.cr:51:11 in 'process'
  from /usr/share/crystal/src/http/server.cr:515:5 in 'handle_client'
  from /usr/share/crystal/src/http/server.cr:468:13 in '->'
  from /usr/share/crystal/src/primitives.cr:266:3 in 'run'
  from /usr/share/crystal/src/fiber.cr:92:34 in '->'
  from ???
Caused by: SSL_connect: Success (RuntimeError)

Though Invidious doesn't seem to crash anymore, which is great!

@syeopite syeopite removed the request for review from a team October 14, 2021 15:50
@syeopite syeopite force-pushed the disable-quic-via-compile-time-flag branch from 345d70f to 4c0a8d9 Compare October 14, 2021 15:50
@syeopite syeopite added the need-testing This feature needs to be deployed and tested to see if it's working, and doesn't break something label Oct 16, 2021
@syeopite
Copy link
Member Author

For anyone that decides to test this PR in the future, could you please monitor the memory usage and crashes? I'm curious if this PR helps in any way, shape, or form on Invidious' general instability.

@unixfox
Copy link
Member

unixfox commented Oct 22, 2021

Could you rebase? Thank you.

@syeopite syeopite force-pushed the disable-quic-via-compile-time-flag branch from 4c0a8d9 to f1f76d2 Compare October 23, 2021 11:14
@syeopite
Copy link
Member Author

Done

@syeopite syeopite force-pushed the disable-quic-via-compile-time-flag branch from f1f76d2 to abc957a Compare October 28, 2021 00:49
# and decompresses. However, explicitly applying it will remove this functionality.
#
# https://github.com/crystal-lang/crystal/issues/11252#issuecomment-929594741
{% unless flag?(:disable_quic) %}
Copy link
Member Author

Choose a reason for hiding this comment

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

TODO: Check for the configuration option as well

Comment on lines +49 to +50
end
else
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
end
else
end
else
{% end %}
# This can likely be optimized into a (small) pool sometime in the future.

Comment on lines +54 to +60
end
{% else %}
# This can likely be optimized into a (small) pool sometime in the future.
HTTP::Client.get("https://yt3.ggpht.com#{url}") do |resp|
return request_proc.call(resp)
end
{% end %}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
end
{% else %}
# This can likely be optimized into a (small) pool sometime in the future.
HTTP::Client.get("https://yt3.ggpht.com#{url}") do |resp|
return request_proc.call(resp)
end
{% end %}
{% unless flag?(:disable_quic) %}
end
{% end %}

Copy link
Member

Choose a reason for hiding this comment

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

This, and the above, avoid duplicate code (only the macro condition is duplicated)

Comment on lines +91 to +95
request_proc = ->(response : HTTP::Client::Response) {
env.response.status_code = response.status_code
response.headers.each do |key, value|
if !RESPONSE_HEADERS_BLACKLIST.includes?(key.downcase)
env.response.headers[key] = value
Copy link
Member

Choose a reason for hiding this comment

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

this, and the code around (headers, response code check) is extremely similar between those three image proxy functions. This could be made into a separate function.

Comment on lines +243 to +253
if CONFIG.use_quic
if YT_POOL.client &.head(thumbnail_resource_path, headers).status_code == 200
name = thumb[:url] + ".jpg"
break
end
else
if HTTP::Client.head("https://i.ytimg.com#{thumbnail_resource_path}").status_code == 200
name = thumb[:url] + ".jpg"
break
end
end
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering something: why isn't the if CONFIG.use_quic check made at the YT_POOL pool level, rather than here?

@syeopite syeopite force-pushed the disable-quic-via-compile-time-flag branch from abc957a to 65fbdbf Compare November 12, 2021 11:56
@syeopite
Copy link
Member Author

syeopite commented Nov 12, 2021

Just added a commit to disable quic by default due to #2577. Once merged, assuming the user hasn't modified the use_quic attribute, Invidious will work again ootb.

@TheFrenchGhosty TheFrenchGhosty merged commit f707f99 into iv-org:master Nov 12, 2021
@syeopite syeopite deleted the disable-quic-via-compile-time-flag branch November 12, 2021 12:59
@unixfox
Copy link
Member

unixfox commented Nov 12, 2021

For what is QUIC still used in the invidious code?

@syeopite
Copy link
Member Author

QUIC shouldn't be used at all now when either use_quic is turned off, or the compile time flag disable_quic is applied.

To be absolutely certain of that, you can just go with the latter route and remove the dependency entirely from the libs folder.

syeopite added a commit to syeopite/invidious that referenced this pull request Dec 9, 2023
syeopite added a commit to syeopite/invidious that referenced this pull request Apr 25, 2024
syeopite added a commit to syeopite/invidious that referenced this pull request Aug 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need-testing This feature needs to be deployed and tested to see if it's working, and doesn't break something ready
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants