Skip to content

Deadlock may occur on closing file-handle by io.popen. #181

Closed
@hymkor

Description

  1. What version of GopherLua are you using? :
$ git show
commit b0fa786cf4ea360285924c4a7fd42325be57aec8
Merge: 6ea863f 921e332
Author: Yusuke Inuzuka <yuin@inforno.net>
Date:   Mon Apr 16 22:52:41 2018 +0900
  1. What version of Go are you using? :
    * go1.10.3
  2. What operating system and processor architecture are you using? :
    * windows/amd64
  3. What did you do? :

Running the script like dir %windir%\system32 | head -10
( popen_and_break.lua.txt )

local MUCH_OUTPUT_COMMAND="cmd /c dir %windir%\\system32 2>nul"

local pin = io.popen(MUCH_OUTPUT_COMMAND,"r")
if pin then
    local i=0
    for line in pin:lines() do
        i = i + 1
        print(i,line)
        if i > 10 then
            break
        end
    end
    print("try to close")
    pin:close()
    print("done")
end
  1. What did you expect to see? :
$ lua5.1.exe popen_and_break.lua
1        ドライブ C のボリューム ラベルは CDrive です
2        ボリューム シリアル番号は 3485-9E2F です
3
4        C:\WINDOWS\system32 のディレクトリ
5
6       2018/06/09  03:19    <DIR>          .
7       2018/06/09  03:19    <DIR>          ..
8       2018/04/13  01:29    <DIR>          0409
9       2018/05/01  07:44    <DIR>          1029
10      2018/05/01  07:44    <DIR>          1033
11      2018/05/01  07:44    <DIR>          1036
try to close
done
  1. What did you see instead? :
$ glua.exe popen_and_break.lua
1        (mojibake removed - this is not problem)
2        (mojibake removed - this is not problem)
3
4        C:\WINDOWS\system32(mojibake removed) 
5
6       2018/06/09  03:19    <DIR>          .
7       2018/06/09  03:19    <DIR>          ..
8       2018/04/13  01:29    <DIR>          0409
9       2018/05/01  07:44    <DIR>          1029
10      2018/05/01  07:44    <DIR>          1033
11      2018/05/01  07:44    <DIR>          1036
try to close

done was not displayed and the script would not terminate.
After typing Ctrl-C, I could see the message "done".

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions