midori-rb / midori.rb

Lightweight, Flexible and Fast Ruby Web Framework
MIT License
870 stars 57 forks source link

Found a warning about read_nonblock method #139

Closed tzwm closed 6 years ago

tzwm commented 6 years ago
<internal:prelude>:78:in `read_nonblock'
W, [2017-11-01T11:47:20.056698 #1]  WARN -- : 172.1.55.22 - - EOFError <internal:prelude>:78:in `__read_nonblock'
/opt/apps/god_said/.bundle/ruby/2.4.0/gems/midori.rb-0.4.4.1/lib/midori/server.rb:35:in `block (2 levels) in receive_data'

本地测试没有问题,但是放在 k8s 上跑就报了这个错。

代码缩略版大概是:

class Route < Midori::API
  get '/status' do
    'Yoooo!'
  end
end

Midori::Configure.set :bind, '0.0.0.0'
Midori::Runner.new(Route).start
dsh0416 commented 6 years ago

当有一个客户端建立了连接但是没有处理完就主动关闭连接时,midori 会主动抛出这个 EOFError 的 Warning 异常。例如使用 Chrome 浏览器访问网页时,Chrome 会自动发起第二个连接却不发送任何内容以减少第二次请求时头消耗。如果关闭网页,或时间过长,Chrome 主动关闭这一连接就会触发这一 Warning。通常在其他框架下,客户端主动关闭连接会忽略而不是抛出异常,midori 在提示上有一些区别。之后版本可能考虑移除这一提醒。

When a client establish a connection and close it before the process got finished, midori will raise EOFError as warning. For example, when using Chrome, it would automatically establish a second connection but not sending any data to reduce the header time consumption of the next request. If you close the page directly or the connection establishes too long, Chrome will choose to close this extra connection, which would make midori raise this warning. Generally in other frameworks, when clients close connection actively, it would choose to ignore it instead of raising exception. Midori behaves a little different here. We're considering removing this prompt in later versions.

tzwm commented 6 years ago

Got it, thx.