Odd notification / NSCFDictionary error

  • I have an application which loops an arbitrary number of times
    (depending on the number of files being handled), which calls an
    NSTask.  I'm encountering an odd error with pre-Leopard systems where
    if my program loops around 200 times, the following error is called.

    2007-11-26 13:43:29.137 MyApp[3595] Exception raised during posting of
    notification.  Ignored.  exception: *** -[NSCFDictionary
    setObject:forKey:]: attempt to insert nil value

    I've done some research, but I cannot find anything which seems to pin
    point this particular problem.  My guess is that this error is being
    thrown when an NSTaskDidTerminateNotification is called after the task
    is complete.  What I've been able to dig up on this "notification
    exception" might be related to "too many files being opened at once".

    Another odd thing about this situation is that I cannot reproduce the
    problem on Leopard.  However, on earlier systems (Tiger, Panther, and
    Jaguar), the problem exists.  This is a pre-existing issue, so it is
    not something that happened after building on Leopard or anything
    along those lines.

    In my code, I also do make one call to an NSMutableDictionary, which
    does have a [NSDictionary setObject: forKey:] call, but that doesn't
    seem to be the source of the problem since I eliminated that code, and
    the problem persists.

    Any ideas?

    Regards,

    Chad
  • On Dec 4, 2007, at 8:21 PM, Chad Armstrong wrote:

    > I've done some research, but I cannot find anything which seems to
    > pin point this particular problem.  My guess is that this error is
    > being thrown when an NSTaskDidTerminateNotification is called after
    > the task is complete.  What I've been able to dig up on this
    > "notification exception" might be related to "too many files being
    > opened at once".

    I don't know the exact answer to your question, but there are two
    kernel settings which are relevant:

    $ sysctl kern.maxproc
    532

    $ sysctl kern.maxprocperuid
    266

    If you're launching all of these NSTasks simultaneously, it might be a
    problem. It's possible NSTask is somehow smarter about how it spawns
    processes on Leopard. You can manually override these values if you're
    working in a controlled setting.

    > In my code, I also do make one call to an NSMutableDictionary, which
    > does have a [NSDictionary setObject: forKey:] call, but that doesn't
    > seem to be the source of the problem since I eliminated that code,
    > and the problem persists.

    That could be some code getting called in the frameworks. You can
    trying breaking on the -[NSException raise] to see what's up.

        - Scott
  • Thanks for the tip.

    I ran a check, but no zombie processes were sticking around.  I do not
    call -waitUntilExit for any of the tasks.  The NSTask is launched
    ( [myTask launch] ) and it does its stuff.  Once completed, it throws
    the NSTaskDidTerminateNotification, which then moves onto the next step.

    I ran my application again, and once again it stopped right around the
    250 mark.

    2007-12-06 12:20:30.943 MyApp[21317] Exception raised during posting
    of notification.  Ignored.  exception: *** -[NSCFDictionary
    setObject:forKey:]: attempt to insert nil value
    2007-12-06 12:21:45.765 MyApp[21317] Failed to load
    NSSystemInfoPanel.nib

    The last line (Failed to load NSSystemInfoPanel.nib) occurs when I try
    and open the About MyApp menu, after the program has stalled.  Once
    again, this error seems to point that "too many files are open".  When
    my program calls a new task, it gets assigned a new PID, so the PID
    number keeps incrementing (which should be correct), but it does not
    appear that the old task ever stays around, and I am calling the
    following once each iteration is complete.

    [myTask release];
    myTask = nil;

    Regards,

    Chad

    On Dec 6, 2007, at 2:00 PM, <macosx-dev-request...> wrote:

    > Does your code call -waitUntilExit on the NSTasks?  At the underlying
    > UNIX layer, if you don't check the exit status, you will end up with
    > zombie processes that still take up process table entries.
    >
    > If you want to check for this problem, you can do so by looking at the
    > output of the "ps x" command in Terminal.  The STAT column will show
    > "Z" for zombie processes.
  • On Dec 6, 2007, at 8:02 PM, Chad Armstrong wrote:

    > I ran a check, but no zombie processes were sticking around.  I do
    > not call -waitUntilExit for any of the tasks.  The NSTask is
    > launched ( [myTask launch] ) and it does its stuff.  Once completed,
    > it throws the NSTaskDidTerminateNotification, which then moves onto
    > the next step.
    >
    > I ran my application again, and once again it stopped right around
    > the 250 mark.
    >
    > 2007-12-06 12:20:30.943 MyApp[21317] Exception raised during posting
    > of notification.  Ignored.  exception: *** -[NSCFDictionary
    > setObject:forKey:]: attempt to insert nil value
    > 2007-12-06 12:21:45.765 MyApp[21317] Failed to load
    > NSSystemInfoPanel.nib

    What does the 'lsof' command say?

          - Scott
  • Hi,

    Do you have a NSAutoreleasePool inside (not around) your loop, and do
    you release it?

    Stéphane

    On 5 Dec 2007, at 05:21 , Chad Armstrong wrote:

    > I have an application which loops an arbitrary number of times
    > (depending on the number of files being handled), which calls an
    > NSTask.  I'm encountering an odd error with pre-Leopard systems
    > where if my program loops around 200 times, the following error is
    > called.
    >
    > 2007-11-26 13:43:29.137 MyApp[3595] Exception raised during posting
    > of notification.  Ignored.  exception: *** -[NSCFDictionary
    > setObject:forKey:]: attempt to insert nil value
    >
    > I've done some research, but I cannot find anything which seems to
    > pin point this particular problem.  My guess is that this error is
    > being thrown when an NSTaskDidTerminateNotification is called after
    > the task is complete.  What I've been able to dig up on this
    > "notification exception" might be related to "too many files being
    > opened at once".
    >
    > Another odd thing about this situation is that I cannot reproduce
    > the problem on Leopard.  However, on earlier systems (Tiger,
    > Panther, and Jaguar), the problem exists.  This is a pre-existing
    > issue, so it is not something that happened after building on
    > Leopard or anything along those lines.
    >
    > In my code, I also do make one call to an NSMutableDictionary, which
    > does have a [NSDictionary setObject: forKey:] call, but that doesn't
    > seem to be the source of the problem since I eliminated that code,
    > and the problem persists.
    >
    > Any ideas?
    >
    > Regards,
    >
    > Chad
    >
    > _______________________________________________
    > MacOSX-dev mailing list
    > <MacOSX-dev...>
    > http://www.omnigroup.com/mailman/listinfo/macosx-dev
  • >> 2007-12-06 12:20:30.943 MyApp[21317] Exception raised during posting
    >> of notification.  Ignored.  exception: *** -[NSCFDictionary
    >> setObject:forKey:]: attempt to insert nil value
    >> 2007-12-06 12:21:45.765 MyApp[21317] Failed to load
    >> NSSystemInfoPanel.nib
    >
    > What does the 'lsof' command say?

    I have also been using lsof, and I'm not finding anything that looks
    too suspicious.  I when I run it, I see the file that is being worked
    on currently, but no mention of older files at all.

    I'll check again, however, just to double-check.

    >
    > Do you have a NSAutoreleasePool inside (not around) your loop, and do
    > you release it?

    Yes, there is an NSAutoreleasePool that is used in the code (to
    capture output coming from the NSTask), but I explicitly call a [pool
    release] at the end of the method that uses the NSAutoreleasePool.

    - Chad
  • On Dec 7, 2007, at 2:00 PM, <macosx-dev-request...> wrote:

    > What does the 'lsof' command say?
    >
    > - Scott

    Under Leopard, lsof wasn't revealing much.  However, my problem
    doesn't seem to appear in Leopard, but I went back to Tiger and tried
    it again.  This finally seems to be pointing in the right direction!
    My task is making use of a pipe, which is acting as a new "file" or
    resource and it isn't closing properly.

    MyApp 1074 admin    0r  CHR                   3,2      0t0 41792260 /dev/null
    MyApp 1074 admin    1w  CHR                   0,0    0t187 41792772 /dev/
    console
    MyApp 1074 admin    2w  CHR                   0,0    0t187 41792772 /dev/
    console
    MyApp 1074 admin    3r     PSXSHM              4096
    apple.shm.notification_center
    MyApp 1074 admin    4r     PSXSHM              4096          /tmp/
    com.apple.csseed.65
    MyApp 1074 admin    5r     PSXSHM              4096
    apple.shm.notification_center
    ...
    MyApp 1074 admin  38    PIPE 0x2ca56c8    16384
    MyApp 1074 admin  39    PIPE 0x2ca5680    16384
    MyApp 1074 admin  40    PIPE 0x2ca5638    16384
    MyApp 1074 admin  41    PIPE 0x2ca55f0    16384
    MyApp 1074 admin  42    PIPE 0x2ca55a8    16384
    MyApp 1074 admin  43    PIPE 0x2ca5560    16384
    ...
    MyApp 1074 admin  249    PIPE 0x38eeb00    16384
    MyApp 1074 admin  250    PIPE 0x38eeab8    16384
    MyApp 1074 admin  251    PIPE 0x38eea70    16384
    MyApp 1074 admin  252    PIPE 0x38eea28    16384
    MyApp 1074 admin  253    PIPE 0x38ee9e0    16384
    MyApp 1074 admin  254    PIPE 0x38ee998    16384

    After looking back at my code, it appears I forgot to deallocate the
    pipe except at the very end!  Going to test this now, and perhaps this
    will fix my problem.

    Best regards,

    Chad
previous month december 2007 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            
Go to today