Project

General

Profile

Actions

Bug #5119

closed

Infinite Loop with IO#pos and IO#each_byte

Bug #5119: Infinite Loop with IO#pos and IO#each_byte

Added by silverhammermba (Max Anselm) over 14 years ago. Updated over 14 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux]
Backport:
[ruby-core:38609]

Description

f = File.new(ARGV.shift)
i = 0
f.each_byte {puts "%08X" % (f.pos - 1) if (i += 1) % 16 == 1}
f.close

This code produces the expected output but never finishes the each_byte loop, instead hanging with 100% CPU usage.

The process cannot be interrupted and only stops when killed. I started a discussion about this issue on Stack Overflow (http://stackoverflow.com/questions/6852384/ruby-file-io-hang/6868527#6868527). Although no one was able to figure out what was causing the bug, one user fixed the loop by modifying the function flush_before_seek in io.c.

Updated by nobu (Nobuyoshi Nakada) over 14 years ago Actions #1

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r32758.
Max, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • io.c (rb_io_each_byte): rbuf can be refreshed during yield.
    [Bug #5119]
Actions

Also available in: PDF Atom