Bugs: Browse | Submit New | Admin

[#20455] win32-open3: crashes after 170 popen3 operations

Date:
2008-05-30 16:54
Priority:
3
Submitted By:
Nobody
Assigned To:
Park Heesob (phasis68)
Category:
win32-open3
State:
Closed
Summary:
win32-open3: crashes after 170 popen3 operations

Detailed description
OS: XP w/SP2 
C:\Documents and Settings\twasson>ruby -v
ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-mswin32]
win32-open3 (0.2.5)

After looping through an "Open3.popen3", the loop crashes with an IO error. We've tried a few things like
other read verbs (get, read, readlines, etc) and have tried explicitly closing things.

Distilled to it's essence, I think this snippet shows the problem:

require "win32/open3"
i = 1
while (i<200)
        Open3.popen3("dir") do |stdin, stdout, stderr|
        e = stdout.readlines   
	end
puts i
i += 1
	
end



C:\Documents and Settings\me>ruby goober.rb

1
 ... etc ...
170

goober.rb:6:in `readlines': closed stream (IOError)
        from goober.rb:6
        from goober.rb:5:in `popen3'
        from goober.rb:5

The non windows version runs fine on Linux.

Add A Comment: Notepad

Please login


Followup

Message
Date: 2008-06-01 00:59
Sender: Daniel Berger

Park's patch fixes the problem and I've applied it to CVS. It
will be included in the 0.2.6 release. Closing out...

Thanks again for the report.

Dan
Date: 2008-05-31 22:31
Sender: Park Heesob 

I looked into it and made a patch.
Here is a patched win32_pipe_finalize of open3.c

static void win32_pipe_finalize(OpenFile *file, int noraise)
{
   int status;
   if(file->f) {
   	fclose(file->f);
   	file->f = NULL;
   }
   if(file->f2) {
   	fclose(file->f2);
   	file->f2 = NULL;
   }
   if(pid_handle != NULL){
      GetExitCodeProcess(pid_handle, &status);
      CloseHandle(pid_handle);
      if(status != STILL_ACTIVE){
 	   win32_set_last_status(status, file->pid);
      }
   }
}


Regards,

Park Heesob
Date: 2008-05-31 20:06
Sender: Daniel Berger

Yes, I see the same behavior. We'll look into it.

Thanks for the report.

Regards,

Dan

Attached Files:

Name Description Download
No Files Currently Attached

Changes:

Field Old Value Date By
status_idOpen2008-06-01 00:59djberg96
resolution_idNone2008-06-01 00:59djberg96
category_idNone2008-06-01 00:59djberg96
assigned_tonone2008-06-01 00:59djberg96
close_date2008-06-01 00:592008-06-01 00:59djberg96