keypup-io / cloudtasker

Background jobs for Ruby using Google Cloud Tasks
MIT License
153 stars 38 forks source link

SSL on Cloudtasker Local Server #100

Closed dominik1001 closed 7 months ago

dominik1001 commented 1 year ago

Hey guys, Thanks for your great work on cloudtasker. We started using it and noticed the following issue running the local server. Our server is running on https using a self-signed certificate. It was raising the following exception:

#<Thread:0x0000000115e14270 /Users/dominik/.rvm/gems/ruby-3.1.2/gems/cloudtasker-0.13.2/lib/cloudtasker/local_server.rb:74 run> terminated with exception (report_on_exception is true):
/Users/dominik/.rvm/gems/ruby-3.1.2/gems/net-protocol-0.2.1/lib/net/protocol.rb:237:in `rbuf_fill': end of file reached (EOFError)
    from /Users/dominik/.rvm/gems/ruby-3.1.2/gems/net-protocol-0.2.1/lib/net/protocol.rb:199:in `readuntil'
    from /Users/dominik/.rvm/gems/ruby-3.1.2/gems/net-protocol-0.2.1/lib/net/protocol.rb:209:in `readline'
    from /Users/dominik/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/net/http/response.rb:42:in `read_status_line'
    from /Users/dominik/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/net/http/response.rb:31:in `read_new'
    from /Users/dominik/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/net/http.rb:1575:in `block in transport_request'
    from /Users/dominik/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/net/http.rb:1566:in `catch'
    from /Users/dominik/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/net/http.rb:1566:in `transport_request'
    from /Users/dominik/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/net/http.rb:1539:in `request'
    from /Users/dominik/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/net/http.rb:1532:in `block in request'
    from /Users/dominik/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/net/http.rb:966:in `start'
    from /Users/dominik/.rvm/rubies/ruby-3.1.2/lib/ruby/3.1.0/net/http.rb:1530:in `request'
    from /Users/dominik/.rvm/gems/ruby-3.1.2/gems/cloudtasker-0.13.2/lib/cloudtasker/backend/redis_task.rb:208:in `deliver'
    from /Users/dominik/.rvm/gems/ruby-3.1.2/gems/cloudtasker-0.13.2/lib/cloudtasker/local_server.rb:89:in `process_task'
    from /Users/dominik/.rvm/gems/ruby-3.1.2/gems/cloudtasker-0.13.2/lib/cloudtasker/local_server.rb:74:in `block in process_jobs'

I was able to make it work changing the http_client method in redis_task.rb to:

def http_client
        @http_client ||=
          begin
            uri = URI(http_request[:url])
            http = Net::HTTP.new(uri.host, uri.port).tap { |e| e.read_timeout = dispatch_deadline }
            http.use_ssl = true
            http.verify_mode = OpenSSL::SSL::VERIFY_NONE
            http
          end
      end

Do you see any chances to make this configurable, so that this also works locally with https? Thanks, Dominik