Ruby 无法调用 Shippable webhook 端点

Ruby unable to call Shippable webhook endpoint

有一段时间我无法从我的 GitLab 实例中 运行 webhooks。起初我认为它与 GitLab 升级 ~10.0 版本或一些 iptables 有关,但现在我认为它可能更多 Ruby 与如何调用 Shippable 端点有关(在 Ruby 中?)。

在失败的请求站点上,我可以看到以下信息:

首先,我测试了 Wither 我实际上可以从服务器连接到 Shippable

curl --verbose -X POST -H "Content-Type: application/json" -H "X-Gitlab-Event: $event" --data "$json" $url

请求成功,我以为不是iptables的问题(但是我查了一下,没有,没有设置iptables规则)

然后我尝试在 /opt/gitlab/embedded/bin/irb:

中重新创建该请求
require 'net/http'
require 'net/https'

uri = URI.parse(url)
username = uri.userinfo.split(':')[0]
password = uri.userinfo.split(':')[1]

req = Net::HTTP::Post.new(uri.path, {'Content-Type' =>'application/json', 'X-Gitlab-Event' => event})
req.basic_auth username, password
req.body = json
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true

response = http.start { |http| http.request(req) }

然后它像在 GitLab 中一样失败了:

Net::OpenTimeout: execution expired
    from /opt/gitlab/embedded/lib/ruby/2.3.0/net/http.rb:880:in `initialize'
    from /opt/gitlab/embedded/lib/ruby/2.3.0/net/http.rb:880:in `open'
    from /opt/gitlab/embedded/lib/ruby/2.3.0/net/http.rb:880:in `block in connect'
    from /opt/gitlab/embedded/lib/ruby/2.3.0/timeout.rb:101:in `timeout'
    from /opt/gitlab/embedded/lib/ruby/2.3.0/net/http.rb:878:in `connect'
    from /opt/gitlab/embedded/lib/ruby/2.3.0/net/http.rb:863:in `do_start'
    from /opt/gitlab/embedded/lib/ruby/2.3.0/net/http.rb:852:in `start'
    from (irb):142
    from embedded/bin/irb:11:in `<main>'

我的本地机器上发生了有趣的类似事情:curl 成功,而 Ruby 抛出。

此外,我检查过它不应该是基本身份验证、SSL 或 POST 的问题 - 我成功地从我的服务器的 irb POSTed 代码片段在 Bitbucket 上,就像我测试 Shippable 一样网络钩子端点。我什至用几乎相同的请求格式在我的模拟服务器上发布了 Shippable 请求。

此时我很好奇这种行为的原因可能是什么以及如何进一步调试它。我发现在所有失败案例中唯一不变的两个因素是目标(可传送 URI)和客户端(Ruby 的 Net::HTTP)。您还建议我检查什么?

我无法回答具体时间,但问题消失了 - 我假设 GitLab 或 Shippable 更新改变了一些东西,因为挂钩在我没有采取任何行动的情况下再次开始工作。