Skip to content

Datastore: does not work inside Puma webserver #691

Closed

Description

@timanovsky

Would be good to receive independent confirmation, but from what I can tell is that Datastore queries hang if run inside Puma webserver. Same query runs fine from rails console process. Worker processes running other queries/inserts also look to be running ok. All environment is the same.

Web process just hangs when calling dataset.run(query)

Activity

  1. timanovsky commented on May 12, 2016

    @timanovsky
    Author

    Actually same Puma server runs fine on localhost. The problem only manifests on Heroku, in web Dyno, and only using v1beta3 API. Weird

  2. blowmage commented on May 12, 2016

    @blowmage
    Contributor

    @timanovsky I don't know what this is about. I'll investigate. What size are your dynos? How many threads are you running on each one? How many dynos are you running?

  3. timanovsky commented on May 12, 2016

    @timanovsky
    Author

    This is scary: grpc/grpc#6278

  4. blowmage commented on May 12, 2016

    @blowmage
    Contributor

    @timanovsky Is there anything interesting in the logs before the process hangs? Feel free to email me a private gist if you don't want to share publicly.

  5. bmclean commented on May 12, 2016

    @bmclean
    Contributor

    @blowmage Unfortunately I can reproduce this as well on 1 standard professional dyno.

    Puma config:
    threads_count = 5
    workers = 2
    preload_app!

    Heroku logs:

    2016-05-12T18:04:40.011516+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/" request_id=ff9a7f0a-2202-49b3-8f56-376be41623f1 fwd="198.169.134.185" dyno=web.1 connect=20ms service=30000ms status=503 bytes=0
    2016-05-12T18:08:10.052634+00:00 app[web.1]: D0512 18:08:10.052580224      37 chttp2_transport.c:698]     got goaway [0]: 73 65 73 73 69 6f 6e 5f 74 69 6d 65 64 5f 6f 75 74 'session_timed_out'
    
  6. blowmage commented on May 12, 2016

    @blowmage
    Contributor

    @murgatroid99 @nicolasnoble Sorry to pull you guys in on this, but do you have any insight on why the GRPC client would hang on Heroku?

  7. murgatroid99 commented on May 12, 2016

    @murgatroid99

    I don't recognize this specific problem. It would help to have more information. If you run with the environment variable GRPC_TRACE=all, it will output a bunch of log information that might contain something useful (make sure to remove private information).

    The problem could be a bug in the gRPC client, or it could be that the server is not responding properly.

  8. bmclean commented on May 12, 2016

    @bmclean
    Contributor

    @murgatroid99 I added the environment variable GRPC_TRACE=all and the output is captured here.

  9. murgatroid99 commented on May 12, 2016

    @murgatroid99

    What I see happening in that log is: grpc connects to the server, completes a TLS handshake, and starts initializing an HTTP2 stream. And then it suddenly stops, and ~20 seconds later, Heroku kills it. Unfortunately, I don't recognize that failure case.

    Can you open a bug against grpc (https://github.com/grpc/grpc) including that trace and a description of how you encountered the error?

  10. blowmage commented on May 12, 2016

    @blowmage
    Contributor

    Thanks for your help @murgatroid99!

  11. bmclean commented on May 13, 2016

    @bmclean
    Contributor

    OK, will do. @blowmage the gcloud-ruby gcloud.gemspec lists "grpc", "~> 0.13.1". It looks like the current version is 0.14.1. Any chance this has already been fixed?

  12. blowmage commented on May 13, 2016

    @blowmage
    Contributor

    @bmclean We'd like to bump the dependency, but we have an open issue that is blocking us from doing that.

  13. bmclean commented on May 13, 2016

    @bmclean
    Contributor

    @timanovsky Are you able to connect to an actual datastore while running Puma locally? If I run Puma localhost and connect to the datastore emulator it is fine but if I run Puma localhost and connect to my actual datastore it hangs with:
    D0512 21:17:47.508334000 123145307635712 chttp2_transport.c:698] got goaway [0]: 73 65 73 73 69 6f 6e 5f 74 69 6d 65 64 5f 6f 75 74 'session_timed_out'

  14. timanovsky commented on May 13, 2016

    @timanovsky
    Author

    Yes, from local puma with same settings it works. This is Linux VM though.
    On 13 May 2016 6:11 am, "Bryce McLean" notifications@github.com wrote:

    @timanovsky https://github.com/timanovsky Are you able to connect to an
    actual datastore while running Puma locally?

    —
    You are receiving this because you were mentioned.
    Reply to this email directly or view it on GitHub
    #691 (comment)

  15. timanovsky commented on May 13, 2016

    @timanovsky
    Author

    Btw those got goaway log messages are pretty frequent even in normally working processes (local, or non-puma).

  16. 17 remaining items

  17. bmclean commented on Jun 30, 2016

    @bmclean
    Contributor

    @blowmage Unfortunately Puma still hangs. I tried your branch as follows:
    gem 'gcloud', :git => 'https://github.com/blowmage/gcloud-ruby.git', :branch => 'grpc-0.15'
    I ran bundle install and verified that I was now using grpc (0.15.0 universal-darwin).
    I moved the require 'gcloud/datastore' back to the top of the Rails CloudDatastore initializer.
    I ran my app with rails s -e production connected to an actual cloud datastore.
    It still hangs.

  18. timanovsky commented on Jul 22, 2016

    @timanovsky
    Author

    Hello, any updates on this? Unfortunately I have to require "gcloud/datastore" at the top, as I have several functions which do not need dataset object, but work with objects likeGcloud::Datastore::Key. It would be a mess to change all such functions to require "gcloud/datastore"inside.

    Update workaround for those with similar problem:

    require 'gcloud'
    module ::Gcloud
      def self.const_missing(name)
        if name.to_s == 'Datastore'
          require 'gcloud/datastore'
          const_get(name)
        end || super
      end
    end
  19. blowmage commented on Aug 29, 2016

    @blowmage
    Contributor

    Does the 0.20.0 release using grpc 1.0 change this at all?

  20. bmclean commented on Aug 30, 2016

    @bmclean
    Contributor

    @blowmage No, the problem still exists with 0.20.0.

  21. blowmage commented on Sep 1, 2016

    @blowmage
    Contributor

    Can you take a look at #875? I think it might help remove the need for const_missing hacks. It should even allow you to create a Google::Cloud::Datastore::Dataset object in an initializer as long as you don't make any API calls with it before Puma forks the sub-processes.

  22. bmclean commented on Sep 1, 2016

    @bmclean
    Contributor

    @blowmage Sure, I will give it a try.

  23. bmclean commented on Sep 1, 2016

    @bmclean
    Contributor

    @blowmage I tried your branch:
    :git => 'https://github.com/blowmage/gcloud-ruby.git', :branch => 'grpc-delay-require'
    Using an initializer like this:

    
    require 'google/cloud/datastore'
    
    module CloudDatastore
      def self.dataset
        @dataset ||= Google::Cloud.datastore(ENV['GCLOUD_PROJECT'])
      end
    end
    

    and Puma works fine configured with 2 workers.

  24. blowmage commented on Sep 2, 2016

    @blowmage
    Contributor

    Great. Thank you!

  25. quartzmo commented on Sep 7, 2016

    @quartzmo
    Member

    Does the 0.20.1 release (with PR #875) resolve this issue?

  26. bmclean commented on Sep 8, 2016

    @bmclean
    Contributor

    Yes.

  27. quartzmo commented on Sep 9, 2016

    @quartzmo
    Member

    @timanovsky Can you confirm 0.20.1 release (with PR #875) as a fix?

  28. timanovsky commented on Sep 9, 2016

    @timanovsky
    Author

    Seems to work, thanks for fixing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api: datastoreIssues related to the Datastore API.grpctype: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions