lanrion / weixin_authorize

微信 Ruby 高级API weixin_authorize http://github.com/lanrion/weixin_authorize .
MIT License
322 stars 116 forks source link

关于RestClient::RequestTimeout请求超时 #77

Closed wikimo closed 8 years ago

wikimo commented 8 years ago

关于请求超时问题,想请问下得如何排除,设置了timeout也不能很好地解决,服务器配置低容易timeout么?

lanrion commented 8 years ago

捕捉Timeout的异常,然后做while。

wikimo commented 8 years ago

Timeout 设置较长是否可行,目前设置还不算太长,while 相当于死循环了 @lanrion

lanrion commented 8 years ago

Timeout你设置长点试试; while是不是死循环,由你代码决定,搞个计数器,每次重新while sleep一下试试。 请求超时,难道你的是国外的VPS?

wikimo commented 8 years ago

思路大概了解了,就是捕捉异常,失败重试。

阿里云,不过机器配置比较低,1CPU,1G内存,5MB带宽 @lanrion

wikimo commented 8 years ago

另外总是会在一些奇怪的地方报错,是服务器的问题还是别的什么问题,cpu率,内存也够用的 @lanrion

/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/weixin_authorize-1.6.3/lib/weixin_authorize/js_ticket/store.rb:35:in `set_jsticket'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/weixin_authorize-1.6.3/lib/weixin_authorize/js_ticket/store.rb:25:in `refresh_jsticket'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/weixin_authorize-1.6.3/lib/weixin_authorize/js_ticket/object_store.rb:16:in `refresh_jsticket'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/weixin_authorize-1.6.3/lib/weixin_authorize/js_ticket/store.rb:29:in `jsticket'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/weixin_authorize-1.6.3/lib/weixin_authorize/js_ticket/object_store.rb:11:in `jsticket'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/weixin_authorize-1.6.3/lib/weixin_authorize/client.rb:48:in `get_jsticket'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/weixin_authorize-1.6.3/lib/weixin_authorize/client.rb:55:in `get_jssign_package'
lanrion commented 8 years ago

为什么提问题的人,都喜欢只贴一部分的错误信息,然而并没有什么用。 请提供完整的错误信息。

wikimo commented 8 years ago

不好意思,可能上下文信息有点少,跑了3个thin在上面,cpu率不高,内存通过vmstat 查看,swap并未使用,用ab测过并发ab -n 800 -c 250 ,fail 为0,都能成功。主要是有时候成功,有时候报错,这个比较麻烦,通过跟踪感觉都是在这个gem http 请求的地方断掉了,或者没返回,服务器带宽5M 阿里云。 @lanrion

/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/weixin_authorize-1.6.3/lib/weixin_authorize/js_ticket/store.rb:35:in `set_jsticket'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/weixin_authorize-1.6.3/lib/weixin_authorize/js_ticket/store.rb:25:in `refresh_jsticket'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/weixin_authorize-1.6.3/lib/weixin_authorize/js_ticket/object_store.rb:16:in `refresh_jsticket'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/weixin_authorize-1.6.3/lib/weixin_authorize/js_ticket/store.rb:29:in `jsticket'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/weixin_authorize-1.6.3/lib/weixin_authorize/js_ticket/object_store.rb:11:in `jsticket'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/weixin_authorize-1.6.3/lib/weixin_authorize/client.rb:48:in `get_jsticket'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/weixin_authorize-1.6.3/lib/weixin_authorize/client.rb:55:in `get_jssign_package'
/home/wwwroot/wexin_app/releases/231/app/controllers/wechat/orders_controller.rb:148:in `buy'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/abstract_controller/base.rb:198:in `process_action'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_controller/metal/rendering.rb:10:in `process_action'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/abstract_controller/callbacks.rb:20:in `block in process_action'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:117:in `call'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:117:in `call'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:151:in `block in halting_and_conditional'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:151:in `call'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:151:in `block in halting_and_conditional'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:151:in `call'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:151:in `block in halting_and_conditional'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:151:in `call'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:151:in `block in halting_and_conditional'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:169:in `call'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:169:in `block in halting'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:234:in `call'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:234:in `block in halting'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:234:in `call'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:234:in `block in halting'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:169:in `call'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:169:in `block in halting'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:169:in `call'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:169:in `block in halting'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:151:in `call'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:151:in `block in halting_and_conditional'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:92:in `call'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:92:in `_run_callbacks'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:734:in `_run_process_action_callbacks'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:81:in `run_callbacks'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/abstract_controller/callbacks.rb:19:in `process_action'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_controller/metal/rescue.rb:29:in `process_action'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/notifications.rb:164:in `block in instrument'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/notifications.rb:164:in `instrument'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_controller/metal/instrumentation.rb:30:in `process_action'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/abstract_controller/base.rb:137:in `process'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/actionview-4.2.0/lib/action_view/rendering.rb:30:in `process'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_controller/metal.rb:195:in `dispatch'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_controller/metal.rb:236:in `block in action'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/routing/route_set.rb:73:in `call'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/routing/route_set.rb:42:in `serve'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/journey/router.rb:43:in `block in serve'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/journey/router.rb:30:in `each'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/journey/router.rb:30:in `serve'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/routing/route_set.rb:802:in `call'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/config.rb:17:in `call'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/etag.rb:24:in `call'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/conditionalget.rb:25:in `call'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/head.rb:13:in `call'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/middleware/params_parser.rb:27:in `call'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/middleware/flash.rb:260:in `call'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/session/abstract/id.rb:225:in `context'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/session/abstract/id.rb:220:in `call'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/middleware/cookies.rb:560:in `call'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/query_cache.rb:36:in `call'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:647:in `call'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:88:in `call'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:88:in `_run_callbacks'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:734:in `_run_call_callbacks'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/callbacks.rb:81:in `run_callbacks'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/rack/logger.rb:38:in `call_app'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/rack/logger.rb:20:in `block in call'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/tagged_logging.rb:68:in `block in tagged'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/tagged_logging.rb:26:in `tagged'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/tagged_logging.rb:68:in `tagged'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/rack/logger.rb:20:in `call'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.0/lib/action_dispatch/middleware/request_id.rb:21:in `call'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/methodoverride.rb:22:in `call'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/runtime.rb:18:in `call'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/sendfile.rb:113:in `call'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/rack-cors-0.4.0/lib/rack/cors.rb:80:in `call'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/engine.rb:518:in `call'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/application.rb:164:in `call'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/thin-1.6.3/lib/thin/connection.rb:86:in `block in pre_process'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/thin-1.6.3/lib/thin/connection.rb:84:in `catch'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/thin-1.6.3/lib/thin/connection.rb:84:in `pre_process'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/thin-1.6.3/lib/thin/connection.rb:53:in `process'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/thin-1.6.3/lib/thin/connection.rb:39:in `receive_data'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/eventmachine-1.0.7/lib/eventmachine.rb:187:in `run_machine'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/eventmachine-1.0.7/lib/eventmachine.rb:187:in `run'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/thin-1.6.3/lib/thin/backends/base.rb:73:in `start'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/thin-1.6.3/lib/thin/server.rb:162:in `start'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/thin-1.6.3/lib/thin/controllers/controller.rb:87:in `start'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/thin-1.6.3/lib/thin/runner.rb:200:in `run_command'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/thin-1.6.3/lib/thin/runner.rb:156:in `run!'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/gems/thin-1.6.3/bin/thin:6:in `<top (required)>'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/bin/thin:23:in `load'
/home/wwwroot/wexin_app/releases/231/vendor/bundle/ruby/2.2.0/bin/thin:23:in `<main>'
lanrion commented 8 years ago

这段异常还是看不出有什么错误,能不能直接把最顶层的错误信息贴过来?我指的是全部,你可以把敏感信息用其他字符替换。

wikimo commented 8 years ago

这已经都是顶层了,Rails.logger.level = 0。

另外调整timeout/open_timeout 到1000,关闭verify_ssl后,似乎有所好转,但是不知是否还有隐患

@lanrion

lanrion commented 8 years ago

我也是醉了,貌似加了SSL之后,经常有人问timeout,先去除吧。

ChocolateAceCream commented 8 years ago

是不是有防火墙所以ssl老超时-------- 原始邮件 --------主题:Re: [weixin_authorize] 关于RestClient::RequestTimeout请求超时 (#77)发件人:wikimo 收件人:lanrion/weixin_authorize 抄送:这已经都是顶层了,Rails.logger.level = 0。

另外调整timeout/open_timeout 到1000,关闭verify_ssl后,似乎有所好转,但是不知是否还有隐患

@lanrion

—Reply to this email directly or view it on GitHub.

wikimo commented 8 years ago

防火墙确实开了,现在是时好时坏,不稳定,所以感觉就比较难排查 @ChocolateAceCream

关闭ssl后,暂时还算稳定 @lanrion

lanrion commented 8 years ago

@wikimo @ChocolateAceCream 这个项目的CI,跑在国外,一般都会有Timeout出现,所以每次本地跑通了,都是直接忽略CI 超时。。

lanrion commented 8 years ago

先关闭了。