Skip to content

IO#readlines/IO#getc hangs while reading over TCPSocket #4982

@bkutil

Description

@bkutil

👋

Since commit 992ba47, the following script hangs until the other side closes the connection:

server = TCPServer.new 9292

while session = server.accept
    puts "Request"

    while line = session.readline("\r\n")
      puts line.inspect
      break if line == "\r\n"
    end

    puts "Response"

    session.write "HTTP/1.1 200 OK\r\n\r\nOK\n"
    session.flush
    session.close
end

With mruby-io and mruby-socket core mrbgems compiled in, running the above script and then e.g. curl 'http://localhost:9292/' outputs:

Before 992ba47:

Request
"GET / HTTP/1.1\r\n"
"Host: localhost:9292\r\n"
"User-Agent: curl/7.58.0\r\n"
"Accept: */*\r\n"
"\r\n"
Response

After:

Request
"GET / HTTP/1.1\r\n"
"Host: localhost:9292\r\n"
"User-Agent: curl/7.58.0\r\n"
"Accept: */*\r\n"
...

Same happens while calling session.getc in the inner loop. Is this expected behavior? It also doesn't happen with MRI Ruby.

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