1

我是水晶新手,正在尝试生成纤维来检查状态是否完整。这是一些代码。

def fiber_operations()
    status = -1

    spawn do
       while status != 5
           response = HTTP::Client.get "https://api.com/endpoint"
           response_to_hash = JSON.parse response.body
           status = response_to_hash["status"]
           sleep 2.seconds
       end
    end

    Fiber.yield
end

当我创建其中一些时,会发生此错误(在此之前它似乎运行良好):

“生成中未处理的异常:SSL_shutdown:操作正在进行中(Errno)”

编辑:

添加了更多信息,我认为一个玩具示例可能已经足够好,但它可能与 HTTP::Client 相关,所以我添加了它。我正在为一些 api 端点执行 GET 并以这种方式获取状态。也许如果一个 GET 正在进行中,另一个无法打开?如果是这样,该怎么做?

编辑2:

不是一个修复。

4

2 回答 2

1

您可能已经点击了crystal-lang/crystal#3168

我已经编写了这个程序进行测试,它似乎工作:

require "http/client"
require "json"

status = -1

spawn do
  while status != 5
    puts "Pinging..."
    response = HTTP::Client.get "https://randomapi.com/api/6de6abfedb24f889e0b5f675edc50deb?fmt=raw&sole"
    puts "Pong"
    response_to_hash = JSON.parse response.body
    status = response_to_hash[0]["first"].to_s.size
    pp status
  end
  puts "Finish!"
  exit 0
end

Fiber.yield

puts "Post yield"

sleep 20000.seconds # so the main thread doesn't exit yet

我认为这与纤维没有太大关系,但与 Crystal/OpenSSL 错误有关。也许您可以通过块rescue内的异常spawn来查看实际的异常。

于 2016-11-18T00:04:48.840 回答
0

此“错误”与 waitlistt 相关的操作已完成。应该由https://github.com/crystal-lang/crystal/pull/4433修复

现在与 Crystal 0.23.0 一起发布

于 2017-05-19T15:15:07.503 回答