Reputation: 1937
I'm new to crystal and am trying to spawn fibers to check whether a status is complete or not. Here is some code.
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
When I create a few of these this error occurs (it seems to be running fine before this):
"Unhandled exception in spawn: SSL_shutdown: Operation now in progress (Errno)"
EDIT:
Added more information, I thought a toy example may be good enough but it may be related to HTTP::Client so I added it in. I am doing a GET for some api endpoint and get the status that way. Maybe if one GET is in progress another cannot be opened? If so, how to do this?
EDIT 2:
Was not a fix.
Upvotes: 1
Views: 182
Reputation: 1011
This "error" related to waitlistt for operation completed. Should be fixed by https://github.com/crystal-lang/crystal/pull/4433
And now released with Crystal 0.23.0
Upvotes: 0
Reputation: 15620
You may have hit crystal-lang/crystal#3168.
I've written this program for testing, and it seems to work:
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
I don't think this has much to do with the fibers, but with that Crystal/OpenSSL bug. Maybe you can rescue
the exception inside the spawn
block to see the actual exception.
Upvotes: 1