async-websocket icon indicating copy to clipboard operation
async-websocket copied to clipboard

After the computer wakes up from sleeping, my program is stuck without any errors

Open wuminzhe opened this issue 1 year ago • 7 comments

#!/usr/bin/env ruby

require 'async'
require 'async/http/endpoint'
require 'async/websocket/client'

URL = "wss://polkadot-rpc.dwellir.com"

Async do |task|
  endpoint = Async::HTTP::Endpoint.parse(URL)

  Async::WebSocket::Client.connect(endpoint) do |connection|
    connection.write(Protocol::WebSocket::TextMessage.generate({
      "jsonrpc" => "2.0", id: 1, method: "chain_subscribeNewHead", params: []
    }))

    while message = connection.read
      puts message.inspect
    end
  end
end

This is a very simple program that subscribes to new head and prints out it. I found that when my computer is woken up from sleeping, the program will stop working without any errors.

I'm quite new to this gem and async ruby. How do I handle this situation?

wuminzhe avatar Jul 12 '24 05:07 wuminzhe

Interesting. Do you mind describing a bit more about your computer?

ioquatix avatar Jul 12 '24 07:07 ioquatix

Interesting. Do you mind describing a bit more about your computer?

I run the program in ubuntu which is running inside windows 11 wsl2.

I'll try it in macos.

wuminzhe avatar Jul 12 '24 07:07 wuminzhe

It sounds like the connection could be disconnected, but the disconnection is not reported correctly.

ioquatix avatar Jul 12 '24 07:07 ioquatix

macos has no such problem. my macos version is 14.5

wuminzhe avatar Jul 12 '24 08:07 wuminzhe

Thanks for your report. I'll check if I can reproduce it on native Linux.

ioquatix avatar Jul 12 '24 08:07 ioquatix

@ioquatix Thanks for the your great gems. They made it easy for me to make an elegant websocket json-rpc client. But I'm not quite sure if I'm using them correctly. Can you have a look?

The websocket client https://github.com/wuminzhe/scale_rb/blob/main/lib/client/ws_client.rb

examples: https://github.com/wuminzhe/scale_rb/blob/main/examples/ws_client_1.rb https://github.com/wuminzhe/scale_rb/blob/main/examples/ws_client_2.rb https://github.com/wuminzhe/scale_rb/blob/main/examples/ws_client_3.rb https://github.com/wuminzhe/scale_rb/blob/main/examples/ws_client_4.rb

wuminzhe avatar Jul 14 '24 14:07 wuminzhe

Sure, I'll take a look.

I'm glad the libraries made it easy for you. It was one of my goals to make it easier to build such things with Ruby.

ioquatix avatar Jul 15 '24 13:07 ioquatix