RBoy
(RBoy)
19 Maggio 2024, 1:27pm
1
Sto vedendo questo avviso nei log, non sono sicuro da dove provenga. Non l’ho mai visto prima, è iniziato dopo l’aggiornamento da 3.2.0 a 3.3.0.
È l’unico avviso intorno ai timestamp, nessun altro errore/avviso (inizialmente pensavo fosse correlato alle email, ma non vedo errori o email respinte intorno a quel momento).
Installato
3.3.0.beta2-dev
(777b8f6d51 )
Messaggio (4 copie segnalate)
RequestTracker.get_data fallito : Encoding::UndefinedConversionError : "\\xA1" da ASCII-8BIT a UTF-8
Backtrace
/var/www/discourse/lib/middleware/request_tracker.rb:190:in `encode'
/var/www/discourse/lib/middleware/request_tracker.rb:190:in `get_data'
/var/www/discourse/lib/middleware/request_tracker.rb:207:in `log_request_info'
/var/www/discourse/lib/middleware/request_tracker.rb:320:in `call'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/railties-7.0.8.1/lib/rails/engine.rb:530:in `call'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/railties-7.0.8.1/lib/rails/railtie.rb:226:in `public_send'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/railties-7.0.8.1/lib/rails/railtie.rb:226:in `method_missing'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/rack-2.2.9/lib/rack/urlmap.rb:74:in `block in call'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/rack-2.2.9/lib/rack/urlmap.rb:58:in `each'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/rack-2.2.9/lib/rack/urlmap.rb:58:in `call'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/unicorn-6.1.0/lib/unicorn/http_server.rb:634:in `process_client'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/unicorn-6.1.0/lib/unicorn/http_server.rb:739:in `worker_loop'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/unicorn-6.1.0/lib/unicorn/http_server.rb:547:in `spawn_missing_workers'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/unicorn-6.1.0/lib/unicorn/http_server.rb:143:in `start'
/var/www/discourse/vendor/bundle/ruby/3.2.0/gems/unicorn-6.1.0/bin/unicorn:128:in `<top (required)>'
/var/www/discourse/vendor/bundle/ruby/3.2.0/bin/unicorn:25:in `load'
/var/www/discourse/vendor/bundle/ruby/3.2.0/bin/unicorn:25:in `<main>'
Sembra esserci un problema con uno specifico web crawler; non dovrebbe influire su di te.
# This Discourse-Track-View request header is set in `lib/ajax.js`,
# whenever the user navigates between Ember routes, to indicate a
# browser page view.
env_track_view = env["HTTP_DISCOURSE_TRACK_VIEW"]
explicit_track_view = status == 200 && %w[1 true].include?(env_track_view)
# An HTML response to a GET request is tracked implicitly, these do
Qui, c’è un problema con la codifica dell’user agent del crawler in UTF-8, poiché contiene un byte non valido.
scrub dovrebbe fare questo. Forse l’uso del parametro :undef può aiutare qui:
user_agent.encode("utf-8", :undef => :replace)
[51] pry(main)> string = "hello \xa1\x28world\x29".force_encoding("ASCII-8BIT")
=> "hello \xA1(world)"
[52] pry(main)> string.encode('utf-8')
Encoding::UndefinedConversionError: "\xA1" from ASCII-8BIT to UTF-8
from (pry):52:in `encode'
[53] pry(main)> string.encode('utf-8', :undef => :replace)
=> "hello �(world)"
4 Mi Piace
È stata unita una correzione.
main ← Arkshine:fix-crowler-useragent-encoding
opened 04:29PM - 24 May 24 UTC
Meta: https://meta.discourse.org/t/encoding-conversion-error-from-ascii-8bit-to-… utf-8-in-logs/308603/2
Crawler requests for non-UTF-8 user agents that contain invalid bytes generate an exception at two places.
See [`get_data()`](https://github.com/discourse/discourse/blob/main/lib/middleware/request_tracker.rb#L158-L193) function:
* On `encode("utf-8")` that results either in the following error depending on the incoming encoding
* `InvalidByteSequenceError`
* `UndefinedConversionError`
* On matching user-agent with invalid byte results to `ArgumentError`.
_Called from `helper.is_crawler` and `helper.is_mobile`, part of the `AnonymousCache::Helper` class._
This PR does the following:
* Handles `encode()` exceptions by relying on `undef` and `invalid` params to replace the faulty bytes instead of raising an exception. It moved into its own module.
* Provides a safe user agent in `AnonymousCache::Helper.`
The `anonymous_cache_spec.rb` tests are specifically for the methods: `blocked_crawler?`, `key_is_modern_mobile_device?`, and `key_is_old_browser?`.
Hopefully, the implementation is okay.
4 Mi Piace
Questo argomento è stato chiuso automaticamente dopo 3 giorni. Non sono più consentite nuove risposte.