fpillet / NSLogger

A modern, flexible logging tool
Other
5k stars 573 forks source link

Connection Issues: NSLogger in app to desktop application #270

Open jcarroll-mediafly opened 5 years ago

jcarroll-mediafly commented 5 years ago

I'm unsure if anyone else is experiencing this but I'm having major issues getting bonjour setup to work smoothly. The app / client side connects to NSLogger simply using LoggerSetupBonjourForBuildUser(). I'm running latest version (1.9) of the desktop app and I'm on Mojave, using XCode 10. Testing with iOS simulator.

If I run NSLogger desktop app I can see the service running just fine. I confirmed by running dns-sd -B _nslogger-ssl and I can see the instance with the correct name.

I've printed out debug statements and can see NSLogger is correctly trying to attach to the correct instance name, no problem.

Ultimately it just hangs and I see the console say "-> configuring SSL" "-> stream open attempt, waiting for open completion"

Eventually it will try again and usually fail. Maybe after 10 minutes it will connect. Not sure why.

I tried rebooting my router to see if anything funky was going on, and nothing really changed. However, during the reboot when I had no wifi connection it all of sudden started working?! I tested this theory by turning wifi on / off multiple times. If I turned off wifi it ALWAYS worked instantly, but as soon as I turned wifi back on, nslogger would go back to hanging with console output simply ending in "-> stream open attempt, waiting for open completion" again. Its great I found a way to get it to connect...however if my wifi is off I can't get that far into testing the application.

Note: This is my home setup. Which is almost 100% wifi, I don't necessarily have the means to easily plug in. I'm unsure if its a Wifi issue in general or specific to my router (I'm using an apple airport extreme). In the office on the other hand, I'm almost exclusively on wired ethernet, and I never seem to have issues there.

Curious to see if anyone else having issues.

jcarroll-mediafly commented 5 years ago

Quick update. Testing with device over wifi doesn't seem to have this issue.

Appears to be simulator + wifi combination. hm...

isadon commented 5 years ago

Seeing this issue as well. When running in the simulator with wifi no connection gets made between the app and the desktop app of NSLogger until some long (>30s) time elapses. If I disable Wifi upon app launch the connection gets setup correctly immediately.

xilin commented 4 years ago

@jcarroll-mediafly @donileo Did you see the method LoggerWriteStreamCallback is called?

jcarroll-mediafly commented 4 years ago

No, that seems the be when it dies off. That callback is never called. I believe the last set of calls I see in the console is about configuring / searching over bonjour.

fpillet commented 4 years ago

This is a really weird issue and I'm pretty sure there's something specific to your networking setup that makes it fail. When NSLogger tries to connect to the desktop, it already has the target info (IP address, port #) handy so this should definitely work ... unless networking calls are being routed out of the machine.

Would you happen to have some specific networking options set in the sim ?

jcarroll-mediafly commented 4 years ago

I haven't completely tested my theory, but if I choose to not use the LOGGER_DEFAULT_OPTIONS but rather use all those options except kLoggerOption_BrowsePeerToPeer, then simulator + nslogger + wifi only appears to connect consistently.

Here is my console when I simply use defaults, no tweaking of options

LoggerInit defaultLogger=0x0 LoggerSetupBonjour serviceType=(null) serviceName=joe LoggerStart logger=0x7fd7cd000820 Start LoggerWorkerThread LoggerReachabilityCallBack called with flags=0x00000002 -> target became reachable LoggerTryConnect, 0 services registered, current stream=(null) LoggerStopBonjourBrowsing LoggerStartBonjourBrowsing Logger configured to search only the local domain, searching for services on: local. Logger started search for services of type _nslogger-ssl._tcp in domain local. Logger found service: <NSNetService 0x600003ba2000> local. _nslogger-ssl._tcp. joe -1 -> looking for services of name joe LoggerTryConnect, 1 services registe2019-12-17 09:21:14.126831-0600 enabled due to running the app with a debugger attached. red, current stream=(null) -> Trying to open write stream to service <NSNetService 0x600003ba2000> local. _nslogger-ssl._tcp. joe -1 LoggerConfigureAndOpenStream configuring and opening log stream -> configuring SSL -> stream open attempt, waiting for open completion

isadon commented 4 years ago

@jcarroll-mediafly I can also confirm that excluding kLoggerOption_BrowsePeerToPeer from the options makes it work for me. At one point without excluding kLoggerOption_BrowsePeerToPeer it was working fine, and then it the desktop app would fail to launch no matter how many times I ran my Xcode Build. After excluding kLoggerOption_BrowsePeerToPeer voila it worked. Hopefully this information should help isolate where the issue really lies.

tjanela commented 4 years ago

Thanks, @donileo, your tip pointed me in the right direction, but in my case, I also had to disable SSL. See my https://github.com/fpillet/NSLogger/issues/227#issuecomment-573128677