Skip to content

Can't stop client without raising an error #82

Description

@zedalaye

I can't find a way to close a client program using async-websocket without errors.

Here's the error I get when I quit using Ctrl+C :

/home/pierre/.local/share/mise/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/async-2.21.1/lib/async/scheduler.rb:386:in 'IO::Event::Selector::EPoll#select': Interrupt
        from /home/pierre/.local/share/mise/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/async-2.21.1/lib/async/scheduler.rb:386:in 'Async::Scheduler#run_once!'
        from /home/pierre/.local/share/mise/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/async-2.21.1/lib/async/scheduler.rb:425:in 'Async::Scheduler#run_once'
        from /home/pierre/.local/share/mise/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/async-2.21.1/lib/async/scheduler.rb:498:in 'block in Async::Scheduler#run'
        from /home/pierre/.local/share/mise/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/async-2.21.1/lib/async/scheduler.rb:461:in 'block in Async::Scheduler#run_loop'
        from /home/pierre/.local/share/mise/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/async-2.21.1/lib/async/scheduler.rb:458:in 'Thread.handle_interrupt'
        from /home/pierre/.local/share/mise/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/async-2.21.1/lib/async/scheduler.rb:458:in 'Async::Scheduler#run_loop'
        from /home/pierre/.local/share/mise/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/async-2.21.1/lib/async/scheduler.rb:497:in 'Async::Scheduler#run'
        from /home/pierre/.local/share/mise/installs/ruby/3.4.1/lib/ruby/gems/3.4.0/gems/async-2.21.1/lib/kernel/async.rb:34:in 'Kernel#Async'
        from lib/listener.rb:224:in 'MexCWebSocketClient#run'
        from lib/listener.rb:282:in '<main>'

I implemented a simple REPL with a quit command that send { method: "unsubscribe", ... } messages and I wait for the response before shutting down the WebSocket connection using : connection.shutdown and I get this error :

 4.04s     warn: Async::Task [oid=0x1ce0] [ec=0x1ce8] [pid=423165] [2025-01-28 00:03:03 +0100]
               | Task may have ended with unhandled exception.
               |   FrozenError: can't modify frozen IO::Stream::StringBuffer: "\x88\x02\x03\xE8"
               |   → /home/pierre/.local/share/mise/installs/ruby/3.4.1/lib/ruby/3.4.0/openssl/buffering.rb:217 in 'OpenSSL::SSL::SSLSocket#sysread_nonblock'
               |     /home/pierre/.local/share/mise/installs/ruby/3.4.1/lib/ruby/3.4.0/openssl/buffering.rb:217 in 'OpenSSL::Buffering#read_nonblock'

Then I have to Ctrl-C to end the program which then display the same error as above.

Do you have any tips on how to end a WebSocket client properly / gracefullty ?

Many thanks for this amazing piece of code

-- Pierre

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions