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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
bkutil opened this issue Apr 27, 2020 · 1 comment
Closed

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

bkutil opened this issue Apr 27, 2020 · 1 comment

Comments

@bkutil
Copy link

bkutil commented Apr 27, 2020

馃憢

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.

matz added a commit that referenced this issue Apr 28, 2020
matz added a commit that referenced this issue Apr 28, 2020
@matz matz closed this as completed in 3ce459f Apr 28, 2020
matz added a commit that referenced this issue Apr 28, 2020
The behavior is different from CRuby, but we believe this is a right
behavior for mruby, which only supports either ASCII or UTF-8
exclusively; fix #4983, ref #4982

```
$ printf '\xe3\x81' | ruby -e 'p STDIN.readchar'
"\xE3\x81"
```

```
$ printf '\xe3\x81' | mruby -e 'p STDIN.readchar'
"\xE3"
```
@dearblue
Copy link
Contributor

dearblue commented Apr 28, 2020

馃樋 I made a mistake.
Thanks @bkutil for the report!
Thanks @matz for the fix!

matz added a commit that referenced this issue Apr 28, 2020
The behavior is different from CRuby, but we believe this is a right
behavior for mruby, which only supports either ASCII or UTF-8
exclusively; fix #4983, ref #4982

```
$ printf '\xe3\x81' | ruby -e 'p STDIN.readchar'
"\xE3\x81"
```

```
$ printf '\xe3\x81' | mruby -e 'p STDIN.readchar'
"\xE3"
```
mimaki pushed a commit to mruby-Forum/mruby that referenced this issue May 7, 2020
mimaki pushed a commit to mruby-Forum/mruby that referenced this issue May 7, 2020
mimaki pushed a commit to mruby-Forum/mruby that referenced this issue May 7, 2020
mimaki pushed a commit to mruby-Forum/mruby that referenced this issue May 7, 2020
The bug was introduced by mruby#4712. The `getc' problem resurrected.
It should be addressed soon.
mimaki pushed a commit to mruby-Forum/mruby that referenced this issue May 7, 2020
The behavior is different from CRuby, but we believe this is a right
behavior for mruby, which only supports either ASCII or UTF-8
exclusively; fix mruby#4983, ref mruby#4982

```
$ printf '\xe3\x81' | ruby -e 'p STDIN.readchar'
"\xE3\x81"
```

```
$ printf '\xe3\x81' | mruby -e 'p STDIN.readchar'
"\xE3"
```
mimaki pushed a commit to mruby-Forum/mruby that referenced this issue May 7, 2020
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