views:

226

answers:

2

I'm trying to debug a DOM scraping packaged called crowbar. Anyhow, when I run I get:

Error: [Exception... "Component returned failure code: 0xc1f30001 (NS_ERROR_NOT_INITIALIZED) [nsIServerSocket.asyncListen]" nsresult: "0xc1f30001 (NS_ERROR_NOT_INITIALIZED)" location: "JS frame :: chrome://crowbar/content/crowbar.js :: onLoad :: line 375" data: no]
Source File: chrome://crowbar/content/crowbar.js
Line: 375

Basically, asyncListen() is throwing NS_ERROR_NOT_INITIALIZED. This is weird because the line of code immediately before this is a call to init()! I've tried adding:

netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");

just before the call to asyncListen() and it had no effect. Is this a security issue? (btw, in case it matters, this is on a Fedora box, running as root, with selinux disabled)... I've also tried a few different port numbers...

+1  A: 

Here's the source code: http://mxr.mozilla.org/mozilla-central/source/netwerk/base/src/nsServerSocket.cpp#369

Are you sure init() doesn't fail (that's what initializes mFD)? Maybe something closes it before your call?

I would build a debug XULRunner to build a debug version and/or try to get logging output from the app. Unfortunately, I can't figure out what the LOG() macro in that code resolves to, usually it's NSPR logging, but you have to guess the module name in order to enable logging for this module.

Boris Zbarsky (one mozilla core developers) says:

Since you're calling init(), the only other way I see to get an NS_ERROR_NOT_INITIALIZED out of asyncListen is for the thread you're running on to no longer be accepting events... So something odd is happening. Are there in fact multiple threads involved?
Nickolay
A: 

I am too facing this problem. I have derived my code from CrowBar and running it through xulrunner 1.9.1 on Win 7.

I get the problem when I am diconnected from the net. If I am on a network it works. I do have multiple threads [multiple xul elements ]. But I belive I am running it on main thread (I am not sure how I can find current thread though), so thread not listening should not be the issue.

Also I have noted that in nsSocketTransportService2.cpp thread becomes null, so Boris maybe right.

NS_IMETHODIMP
nsSocketTransportService::Dispatch (nsIRunnable *event, PRUint32 flags) 
{

    LOG(("STS dispatch [%p]\n", event));
    nsCOMPtr<nsIThread> thread = GetThreadSafely();
    NS_ENSURE_TRUE(thread, NS_ERROR_NOT_INITIALIZED);
    nsresult rv = thread->Dispatch(event, flags);
    if (rv == NS_ERROR_UNEXPECTED) {
        // Thread is no longer accepting events. We must have just shut it
        // down on the main thread. Pretend we never saw it.
        rv = NS_ERROR_NOT_INITIALIZED;
    }
    return rv;
}

Hope this helps pin down the problem.

thanks harvinder

Harvinder Singh