nsSocketTransport is of two minds in different spots about whether local sockets should be kept open when offline. When IOService is set to offline mode, among other things, it tells nsSocketTransportService to take itself offline. When the STS goes offline, it detaches all its sockets --- except those which, according to their handlers, are 1) local, and 2) should be kept when offline. (This is all nsSocketTransportService::DetachSocketWithGuard, in netwerk/base/src/nsSocketTransportService2.cpp.) The nsASocketHandler class, which nsSocketTransport inherits from, declares the IsLocal and KeepWhenOffline member functions. The default definition of KeepWhenOffline says "no" --- local sockets should be detached when we go offline, unless the derived class overrides that. nsSocketTransport does not. However, while nsSocketTransportService::InitiateSocket does check gIOService->IsOffline for the purpose of returning an NS_ERROR_OFFLINE code, it explicitly *permits* sockets with local addresses to proceed. Perhaps I'm missing something really subtle here, but that combination of behaviors doesn't make any sense. KeepWhenOffline is only overridden for server sockets; there isn't any way to create nsSocketTransports whose KeepWhenOffline returns "yes, please." And even if InitiateSocket were to allow a local socket's creation to go forward when the STS was offline, I would expect that putting the STS online and then taking it offline again would detach the socket anyway. Since the check in InitiateSocket was explicitly added in the fix for bug 87717 (not a typo), I assume that code actually relies on that behavior: nsSocketTransport instances for local addresses should always be kept around in offline mode. That suggests that the fix is for nsSocketTransport to override KeepWhenOffline to return true, to protect the sockets when offline.
The test to write, here, would be one that creates a local socket while offline, and then switches IOService back online and then offline, and verifies that the local socket is unaffected.
Rats. I wasn't missing something subtle, I was missing the '!' in nsSocketTransportService::DetachSocketWithGuard. Sockets are retained if their are local *or* if they should be kept when offline. So the test in InitiateSocket is correct in assuming that, if the socket is local, it should be created even if we are offline; and KeepWhenOffline definitely should *not* be overridden, lest all transports be retained.