Search code examples
ruby-on-railsterminalsidekiqworker

Sidekiq worker displaying 'ERROR: heartbeat: "\xE2" from ASCII-8BIT to UTF-8' every two seconds


I am a junior dev working on a Ruby on Rails App that uses React on the front end. Recently I started getting this error and have no idea what is causing it. Has anyone seen this before? enter image description here

If the image doesn't show this is what the terminal is giving back:

2020-08-14T16:14:36.743Z 37931 TID-oxmbyiczg INFO: See LICENSE and the LGPL-3.0 for licensing details.
2020-08-14T16:14:36.743Z 37931 TID-oxmbyiczg INFO: Upgrade to Sidekiq Pro for more features and support: http://sidekiq.org
2020-08-14T16:14:36.743Z 37931 TID-oxmbyiczg INFO: Booting Sidekiq 5.0.5 with redis options {:id=>"Sidekiq-server-PID-37931", :url=>nil}
2020-08-14T16:14:36.748Z 37931 TID-oxmbyiczg INFO: Starting processing, hit Ctrl-C to stop
2020-08-14T16:14:36.757Z 37931 TID-oxmddbzao ERROR: heartbeat: "\xE2" from ASCII-8BIT to UTF-8
2020-08-14T16:14:41.773Z 37931 TID-oxmddbzao ERROR: heartbeat: "\xE2" from ASCII-8BIT to UTF-8
2020-08-14T16:14:46.776Z 37931 TID-oxmddbzao ERROR: heartbeat: "\xE2" from ASCII-8BIT to UTF-8
2020-08-14T16:14:51.783Z 37931 TID-oxmddbzao ERROR: heartbeat: "\xE2" from ASCII-8BIT to UTF-8```

Solution

  • A little background: processSets iterate over the workers and they in turn send a heartbeat to redis every five seconds to check uptime and connectivity with the redis instance.

    First I would check the Encoding::default_external on server and client machines and ensure Encoding::UTF_8 is set for both. Secondly ensure config.encoding = "utf-8" is set in application.rb of where the worker is running.

    But the above is all very general and does not explain the error you are seeing, that comes from this block:

    def ❤(key, data)
      begin
        # logic
      rescue => e
        # ignore all redis/network issues
        logger.error("heartbeat: #{e.message}")
      end
    end
    

    The above is called from heartbeat which is called from start_heartbeat which is called in run. The key used for heartbeat comes from the identity method in util.rb (in the Sidekiq repo) which comes from hostname which is a method which calls Socket.gethostname which does what it says in getting the hostname of the server, which returns the hostname in the platform specific encoding.

    So if we had to come this far, find the server name of the machine running the worker and spin up a console and check the encoding value of Socket.gethostname which should explain the error.