Reputation: 21905
I've written an open source Rack app and core lirary to stream stock quotes from Tradeking.com. Here's the rack app: https://github.com/chaddjohnson/trading_websocket_service. And here's the core library: https://github.com/chaddjohnson/trading_core.
I modified trading_core/lib/trading_core/quote_streamer/tradeking.rb to output streamed data to the console, as so:
@http.stream do |data|
puts data
After a few hours of it streaming and outputting to the console, it simply freezes. I have absolutely no idea why. I've done my best to ensure that any loops are not infinite. I've been debugging this for over a week now.
Any ideas why this is happening?
Here are the main files where I think this could be happening:
Upvotes: 1
Views: 182
Reputation: 13531
Glad I could push you in the right direction!
My first hunches were about open connections:
You might need to make sure you close the connection: @http.close in an ensure block at the end of the method you referenced
Then on to some forensics:
Sounds like you'll have to dig into the ruby process you're running to figure out what's choking it up. Depending on what OS you're on of course, on mac and linux you can use tools like gdb, strace, dtrace, etc. For example: ruby.dzone.com/articles/debugging-stuck-ruby-processes
We found that select
was being called a lot which led us to keep our suspicion on the connections. Turns out the problem was in reusing a dead connection via @api ||= ...init code...
Glad you were able to find what it was! And thanks for posting your solution!
Upvotes: 1
Reputation: 1008
On the first look at your code I could imagine two reasons for your issues:
Upvotes: 1