Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebSocket frame size is too small (125 bytes) #172

Closed
hyrious opened this issue Jul 23, 2019 · 3 comments
Closed

WebSocket frame size is too small (125 bytes) #172

hyrious opened this issue Jul 23, 2019 · 3 comments

Comments

@hyrious
Copy link

hyrious commented Jul 23, 2019

Steps to reproduce

Run this little script:

require 'midori.rb'

class AppRoute < Midori::API
  capture Errno::ENOENT do |e|
    @status = 404
    "Not found"
  end

  websocket '/' do |ws|
    ws.on :open do
      ws.send '125 bytes: ok'
      ws.send '1' * 125
      ws.send '126 bytes: fail'
      ws.send '1' * 126
      ws.send 'pipe is broken'
    end
  end

  get '/' do
    <<~HTML
      <!DOCTYPE html>
      <meta charset="UTF-8">
      <title>Midori Issue WebSocket</title>
      <p>Open the console to see errors.</p>
      <script>
        var ws = new WebSocket('ws://localhost:8080');
        ws.addEventListener('message', function (e) {
          console.log(e.data);
        });
      </script>
    HTML
  end
end

begin
  Midori::Runner.new(AppRoute).start
rescue Interrupt
  puts "See you next time."
rescue => e
  puts "#{e.class}: #{e}"
  retry
end

Error messages will be shown both in the browser console and the terminal.

Expected behavior

WebSocket frame size has a limit of 2^63 bytes (if we correctly implement it according to the RFC).

Actual behavior

ws.send '1' * 126 suddenly broke the socket, but the error shows until a new message is about to send (say, ws.send 'pipe is broken').

System configuration

Midori version: 0.7.0

Ruby version: 2.6.3

@dsh0416
Copy link
Member

dsh0416 commented Jul 27, 2019

Thank you for your report. The bug has confirmed. I'm working on fixing it.

@dsh0416
Copy link
Member

dsh0416 commented Jul 27, 2019

I've just submitted a patch #173 . It may require more testing before merging.

@dsh0416
Copy link
Member

dsh0416 commented Jul 28, 2019

Bug fixed. Thank you so much for your submission.

@dsh0416 dsh0416 closed this as completed Jul 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants