Bwana: hang while generating index

Any trouble you encounter with the Pedias, here's the place to ask for help.
Post Reply
FZiegler
Junior Member
Junior Member
Posts: 3
Joined: Sat Jun 02, 2007 9:32 am

Bwana: hang while generating index

Post by FZiegler »

I love Bwana!

One slight problem, though. I've added MANPATH /opt/local/share/man in /usr/share/misc/man.conf so that it reads MacPorts-installed manpages. This works fine (e.g. "man:svn" in Safari's address bar), except that with just "man:", it hangs at "Please be patient, Bwana is building descriptions to make the index more useful" and I have no choice but to kill it in Terminal.

The hang happens after 245 (or once I saw 252) of the 280 gzipped manpages in the man1 subdirectory have been expanded in /private/var/tmp/folders.501/; if I move all 280 out of the way, it still happens after 245 (of 1638) pages in man3 have been expanded. At that point console.log says

Code: Select all

2007-06-02 10:12:01.662 Bwana[21116] *** -[NSCFDictionary setObject:forKey:]: attempt to insert nil value
Unfortunately I've not been able to follow this all the way in gdb, because (I think) I don't know how to prevent it from interfering with the system call to gunzip: under gdb things hang before any unzipping, and console.log prints

Code: Select all

2007-06-02 10:20:33.506 Bwana[22123] *** -[NSConcreteFileHandle readDataOfLength:]: Interrupted system call
The best I could is manage is a backtrace right before that, by stopping at SIGCHLD:

Code: Select all

mini:~ fz$ gdb
GNU gdb 6.1-20040303 (Apple version gdb-437) (Fri Jan 13 18:45:48 GMT 2006)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-apple-darwin".
(gdb) attach 22123
Attaching to process 22123.
Reading symbols for shared libraries . done
Reading symbols for shared libraries ........................................................................... done
0x9000a4e7 in mach_msg_trap ()
(gdb) handle SIGCHLD stop
Signal        Stop      Print   Pass to program Description
SIGCHLD       Yes       Yes     Yes             Child status changed
(gdb) c
Continuing.
Reading symbols for shared libraries . done (**)

Program received signal SIGCHLD, Child status changed.
0x900107ec in read ()
(gdb) bt
#0  0x900107ec in read ()
#1  0x9279032f in -[NSConcreteFileHandle readDataOfLength:] ()
#2  0x92791387 in -[NSConcreteFileHandle readDataToEndOfFile] ()
#3  0x000038f5 in -[MyController unzip:] ()
#4  0x0000479d in -[MyController showIndexWithFilter:inNewWindow:usingCache:] ()
#5  0x00003526 in -[MyController showIndexWithFilter:inNewWindow:] ()
#6  0x000034f3 in -[MyController masterIndex:] ()
#7  0x9271dd35 in -[NSAppleEventManager dispatchRawAppleEvent:withRawReply:handlerRefCon:] ()
#8  0x9271db5f in _NSAppleEventManagerGenericHandler ()
#9  0x9150dfb5 in aeDispatchAppleEvent ()
#10 0x9150dee6 in dispatchEventAndSendReply ()
#11 0x9150ddb2 in aeProcessAppleEvent ()
#12 0x92efc2cc in AEProcessAppleEvent ()
#13 0x9339aca9 in _DPSNextEvent ()
#14 0x9339a6be in -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] ()
#15 0x93394443 in -[NSApplication run] ()
#16 0x93388397 in NSApplicationMain ()
#17 0x00002926 in _start ()
#18 0x0000284d in start ()
(gdb) c (***)
Continuing.
Here (**) is where I enter "man:" in Safari, and (***) is where console prints "Interrupted system call". Without this interrupt I guess I'd see the stack build up to where a nil is passed to [NSCFDictionary setObject:forKey:] and could investigate variables, but I haven't been able to get there. Any ideas?
FZiegler
Junior Member
Junior Member
Posts: 3
Joined: Sat Jun 02, 2007 9:32 am

Post by FZiegler »

This trace goes a little further:

Code: Select all

mini:~ fz$ gdb
GNU gdb 6.1-20040303 (Apple version gdb-437) (Fri Jan 13 18:45:48 GMT 2006)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-apple-darwin".
(gdb) attach 22213
Attaching to process 22213.
Reading symbols for shared libraries . done
Reading symbols for shared libraries ........................................................................... done
0x9000a4e7 in mach_msg_trap ()
(gdb) fb -[NSException raise]
Breakpoint 1 at 0x927531e1
(gdb) c
Continuing.
Reading symbols for shared libraries . done
Reading symbols for shared libraries ........... done
Reading symbols for shared libraries . done
Reading symbols for shared libraries ....... done (**)

Breakpoint 1, 0x927531e1 in -[NSException raise] ()
(gdb) bt
#0  0x927531e1 in -[NSException raise] ()
#1  0x92779fdb in +[NSException raise:format:] ()
#2  0x92809662 in _NSFileHandleRaiseOperationException ()
#3  0x92790341 in -[NSConcreteFileHandle readDataOfLength:] ()
#4  0x92791387 in -[NSConcreteFileHandle readDataToEndOfFile] ()
#5  0x000038f5 in -[MyController unzip:] ()
#6  0x0000479d in -[MyController showIndexWithFilter:inNewWindow:usingCache:] ()
#7  0x00003526 in -[MyController showIndexWithFilter:inNewWindow:] ()
#8  0x000034f3 in -[MyController masterIndex:] ()
#9  0x9271dd35 in -[NSAppleEventManager dispatchRawAppleEvent:withRawReply:handlerRefCon:] ()
#10 0x9271db5f in _NSAppleEventManagerGenericHandler ()
#11 0x9150dfb5 in aeDispatchAppleEvent ()
#12 0x9150dee6 in dispatchEventAndSendReply ()
#13 0x9150ddb2 in aeProcessAppleEvent ()
#14 0x92efc2cc in AEProcessAppleEvent ()
#15 0x9339aca9 in _DPSNextEvent ()
#16 0x9339a6be in -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] ()
#17 0x93394443 in -[NSApplication run] ()
#18 0x93388397 in NSApplicationMain ()
#19 0x00002926 in _start ()
#20 0x0000284d in start ()
(gdb) c
Continuing.

Breakpoint 1, 0x927531e1 in -[NSException raise] ()
(gdb) bt
#0  0x927531e1 in -[NSException raise] ()
#1  0x9271dd9b in -[NSAppleEventManager dispatchRawAppleEvent:withRawReply:handlerRefCon:] ()
#2  0x9271db5f in _NSAppleEventManagerGenericHandler ()
#3  0x9150dfb5 in aeDispatchAppleEvent ()
#4  0x9150dee6 in dispatchEventAndSendReply ()
#5  0x9150ddb2 in aeProcessAppleEvent ()
#6  0x92efc2cc in AEProcessAppleEvent ()
#7  0x9339aca9 in _DPSNextEvent ()
#8  0x9339a6be in -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] ()
#9  0x93394443 in -[NSApplication run] ()
#10 0x93388397 in NSApplicationMain ()
#11 0x00002926 in _start ()
#12 0x0000284d in start ()
(gdb) c
Continuing. (***)
^C
Program received signal SIGINT, Interrupt.
0x9000a4e7 in mach_msg_trap ()
(gdb) q
The program is running.  Quit anyway (and detach it)? (y or n) y
Detaching from process 22213 thread 0xd03.
mini:~ fz$ 
Again, (**) is where I enter "man:" in Safari, and (***) is where console prints "Interrupted system call", at which point Bwana hangs and I kill it. But, BIG DIFFERENCE, this time it has managed to gunzip

Code: Select all

mini:~ fz$ ls -l /private/var/tmp/folders.501/TemporaryItems/ 
total 104
-rw-r--r--   1 fz  wheel  34779 Jun  2 12:08 bsdmake.1.txt
-rw-r--r--   1 fz  wheel   3167 Jun  2 12:08 cal.1.txt
-rw-r--r--   1 fz  wheel   9222 Jun  2 12:08 calendar.1.txt
which are the first three from

Code: Select all

mini:~ fz$ ls -l /usr/share/man/man1/ | grep '.gz'
-r--r--r--    1 root  wheel   11394 Jan 13  2006 bsdmake.1.gz
-r--r--r--    1 root  wheel    1607 Jan 13  2006 cal.1.gz
-r--r--r--    1 root  wheel    3812 Jan 13  2006 calendar.1.gz
-r--r--r--    1 root  wheel    2163 Jan 13  2006 checknr.1.gz
-r--r--r--    1 root  wheel    2008 Jan 13  2006 colcrt.1.gz
-r--r--r--    1 root  wheel    1674 Jan 13  2006 crontab.1.gz
-r--r--r--    1 root  wheel    1111 Jan 13  2006 getNAME.1.gz
-rw-r--r--    2 root  wheel      16 Jan 13  2006 gzcat.1
-rw-r--r--    1 root  wheel    1296 Jan 13  2006 gzexe.1
-rw-r--r--    1 root  wheel   16140 Jan 13  2006 gzip.1
-r--r--r--    1 root  wheel    1506 Jan 13  2006 intro.1.gz
-r--r--r--    1 root  wheel    1683 Jan 13  2006 leave.1.gz
-r--r--r--    1 root  wheel    1540 Jan 13  2006 lock.1.gz
-r--r--r--    1 root  wheel    1735 Jan 13  2006 mesg.1.gz
-r--r--r--    1 root  wheel    1704 Jan 13  2006 tsort.1.gz
-r--r--r--    1 root  wheel    2434 Jan 13  2006 units.1.gz
-r--r--r--    2 root  wheel    2245 Jan 13  2006 uudecode.1.gz
-r--r--r--    2 root  wheel    2245 Jan 13  2006 uuencode.1.gz
-r--r--r--    1 root  wheel    1854 Jan 13  2006 write.1.gz
mini:~ fz$ 

(Also, I forgot to mention this is Bwana 2.1 on an Intel Mac mini running Mac OS X 10.4.6.)
FZiegler
Junior Member
Junior Member
Posts: 3
Joined: Sat Jun 02, 2007 9:32 am

Post by FZiegler »

OK, it looks like the problem is: if we're going to open all those gzipped manpages, we had better close them as we go, lest we hit the ulimit of 256 open file descriptors.

(For background see this thread: NSPipe can return nil.)

The following patch appears to solve the problem for me:

Code: Select all

diff -ur Bwana.orig/Bwana.xcodeproj/project.pbxproj Bwana/Bwana.xcodeproj/project.pbxproj
--- Bwana.orig/Bwana.xcodeproj/project.pbxproj  2007-04-14 10:32:37.000000000 -0400
+++ Bwana/Bwana.xcodeproj/project.pbxproj       2007-06-04 22:25:36.000000000 -0400
@@ -26,25 +26,6 @@
                8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
 /* End PBXBuildFile section */
 
-/* Begin PBXBuildRule section */
-               050ADEFE09498F6B00082E31 /* PBXBuildRule */ = {
-                       isa = PBXBuildRule;
-                       compilerSpec = com.apple.compilers.gcc.3_3;
-                       fileType = sourcecode.c;
-                       isEditable = 1;
-                       outputFiles = (
-                       );
-               };
-               050ADEFF09498F7000082E31 /* PBXBuildRule */ = {
-                       isa = PBXBuildRule;
-                       compilerSpec = com.apple.compilers.gcc.3_3;
-                       fileType = sourcecode.asm;
-                       isEditable = 1;
-                       outputFiles = (
-                       );
-               };
-/* End PBXBuildRule section */
-
 /* Begin PBXFileReference section */
                05265E6C0B2FFDE100B55AEE /* license.txt */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = license.txt; sourceTree = "<group>"; };
                05265F0B0B30073100B55AEE /* dog.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = dog.png; sourceTree = "<group>"; };
@@ -190,8 +171,6 @@
                                8D11072E0486CEB800E47090 /* Frameworks */,
                        );
                        buildRules = (
-                               050ADEFF09498F7000082E31 /* PBXBuildRule */,
-                               050ADEFE09498F6B00082E31 /* PBXBuildRule */,
                        );
                        dependencies = (
                        );
@@ -342,7 +321,7 @@
                050ADEF909498F3500082E31 /* Debug */ = {
                        isa = XCBuildConfiguration;
                        buildSettings = {
-                               ARCHS = ppc;
+                               ARCHS = "$(NATIVE_ARCH)";
                                SDKROOT = /Developer/SDKs/MacOSX10.4u.sdk;
                        };
                        name = Debug;
diff -ur Bwana.orig/MyController.m Bwana/MyController.m
--- Bwana.orig/MyController.m   2007-04-14 10:30:55.000000000 -0400
+++ Bwana/MyController.m        2007-06-04 22:16:50.000000000 -0400
@@ -677,6 +677,7 @@
                pathToManual = [self manualPageFor:[manualPage stringByDeletingPathExtension] section:section];
        }
 
+    [findPathHandle closeFile];
        return pathToManual;
 }
 
@@ -705,6 +706,7 @@
                [unzippedString writeToFile:unzippedPath atomically:NO];
        }
 
+    [gunzipHandle closeFile];
        return unzippedPath;
 }
 
@@ -725,6 +727,7 @@
                asciiFormatedOutput = [[[NSString alloc] initWithData:dataRecieved encoding:NSASCIIStringEncoding] autorelease];
        }
 
+    [groffHandle closeFile];
        return asciiFormatedOutput;
 }
(Note that I also had to remove the gcc.3_3 build rules which are not supported in Intel-based Macs, causing

Code: Select all

gcc-3.3: installation problem, cannot exec `cc1obj': No such file or directory
.)

I hope this can be useful to others.
User avatar
Conor
Top Dog
Posts: 5346
Joined: Sat Jul 03, 2004 12:58 pm
Contact:

Post by Conor »

That is one useful post. Thank you for that bug fix and all that work. I have added closeFile call to all the handles in the NSTasks methods as your diff file noted. Also added the "GCC_VERSION_i386 = 4.0" to the debug rules as this was probably causing the problem for your Intel debug build, the variable was only present in release build.

A useful trick for debugging in the future is to add a breakpoint at -[NSException raise] with Xcode. This stops the stack trace on the majority of bugs in Cocoa in this case "-[NSCFDictionary setObject:forKey:]: attempt to insert nil value".

Also added "FZiegler" to the minimal credits inside the source and read me, (I do need to add an about panel one of these days).

Thank you,
Conor
Post Reply