AirConnect icon indicating copy to clipboard operation
AirConnect copied to clipboard

Attempting to connect to Sonos from iOS AirPlay makes it unavailable on macOS

Open dpo opened this issue 2 years ago • 18 comments

Hi. First of all, many thanks for developing this bridge, which is a life saver!

I'm on a M1 Mac running macOS 12.6.3. I have airupnp-macos-arm64-static from the master branch running via launchctl. When I first load the service, my Sonos Connect:Amp (an older model) becomes available, and I can connect to it from macOS without any problem.

However, if I try to connect to it from my iPhone or iPad via AirPlay, two things happen:

  1. the connection is never established
  2. I can no longer connect to it from macOS either afterwards.

I monitored the log file, but no messages are logged as the iPhone/iPad is trying to connect, or as macOS tries to connect afterwards.

Using launchctl unload ... / launchctl load ... again refreshes everything and the Connect:Amp becomes available again from macOS.

It used to be (at least in my case) that running your bridge would make the Sonos Connect:Amp available to iOS devices via AirPlay.

I should mention that I recently changed router, and that may be the issue.

What would be your recommendations to try and debug this situation?

For what it's worth, here's my log file: https://gist.github.com/dpo/a69d32b5a50b13315f9c571c0e06e6c7

Thanks in advance!

dpo avatar Mar 24 '23 23:03 dpo

FWIW, in the log file, the one named "Office" is the older Connect:Amp (this one]. The one named "Living Room" is a new Connect:Amp (this one].

Here's an additional clue: if I run the executable directly from the command line with no specific options, I can connect to the older Amp from macOS. If I try to connect from iOS, it fails, and subsequently, trying to connect from macOS also fails (as happens when run as a service). However, trying to quit the program with C-c or exit does not work. The program hangs at

^C[10:52:59.860351] Stop:1148 terminate update thread ...
[10:52:59.860365] Stop:1153 flush renderers ...

Here's a log with debug information turned on in hopes something in there may be useful: https://gist.github.com/dpo/533db2a30ca044261ea69268a80b281f

dpo avatar Mar 28 '23 15:03 dpo

Isn't there more in the log? Best is to compress and attach it

philippe44 avatar Mar 28 '23 17:03 philippe44

There's nothing else in the first log. The second log keeps getting added to, but as I mentioned, when I try C-c or exit, the program hangs.

dpo avatar Mar 28 '23 18:03 dpo

But there is not even a playback session in that log

philippe44 avatar Mar 28 '23 23:03 philippe44

That's because I can't get connected. I can play from the Mac if I don't try to connect from iOS first.

dpo avatar Mar 29 '23 01:03 dpo

Is there any additional info I can post to help?

dpo avatar Apr 01 '23 00:04 dpo

So if you launch manually the app, don't get any iOS to connect can you type exit on the bridge command line and does it exit. Then can you confirm that after one such successful connection, you cannot exit anymore.

It's likely a player that is stuck in a infinite wait loop and I have a few ideas where but I'd need to be more precise to not waste too much time

philippe44 avatar Apr 01 '23 08:04 philippe44

Here are the results of the experiments you asked:

  1. Launch manually, don't try to connect from iOS, type exit. Result: the app exits normally. Log: https://gist.github.com/dpo/9a484730d56c0d55be62c5507a7477f0
  2. Launch manually, don't try to connect from iOS, connect from macOS, play something, stop playing, type exit. Result: connection OK, playback OK, app exits normally. Log: https://gist.github.com/dpo/d047b8641140ecb7d9ebf7c1471639b5
  3. Launch manually, try to connect from iOS:
    • interestingly, when I tried yesterday, it worked. I was able to play back from my iPad. I disconnected, reconnected, and it all seemed to work. I launched the process as a service and it worked too. Here is yesterday's log file, where you can see playbacks happening: https://gist.github.com/dpo/7fade5f8cb30ca82bb7fc3aa3ec53b07. You can see a long break during the night. When I tried to reconnect this morning, I was no longer able to connect. The termination occurs because I run launchctl unload to stop the service. I restarted it but was not able to connect either. I eventually stopped it.
    • Today, I can no longer connect from iOS, and typing exit at the command line fails to exit. Log file: https://gist.github.com/dpo/1b2e1e9ef0989ebf8e4f5e8bd606cf53.

I don't believe anything changed on my system between yesterday and today. There were no OS updates.

I hope the above is helpful. If you would like me to run more experiments, please let me know.

Thank you.

dpo avatar Apr 02 '23 16:04 dpo

Do you have some kind of firewall running on that Mac? The failure to connect and exit both point toward the same cause : the RTSP server is listening on a socket that is blocked from being accessed. It prevents iPhone or iPad to access and it also prevents the exit to happen because exiting requires an access to that same server.

philippe44 avatar Apr 02 '23 18:04 philippe44

Ok - I've changed the way I wait for incoming connection, using a busy loop instead. There are pros and cons in doing that, but at least it should be more foolproof in term of system locking app because of obscure accept() failure.

Anyway, can you give a try to 1.0.17?

philippe44 avatar Apr 02 '23 19:04 philippe44

I downloaded 1.0.17 but it gets killed immediately upon launch by the OS:

~/bin ❯ ./airupnp-macos-arm64-static                                                                                                ✘ KILL 17:52:49
zsh: killed     ./airupnp-macos-arm64-static

dpo avatar Apr 02 '23 21:04 dpo

can you try the x86 version?

philippe44 avatar Apr 02 '23 21:04 philippe44

YEAH! Amazing! So far so good. I can play from both macOS and iOS. I can switch back and forth, and typing exit closes the program normally. Thank you!!!

I'll keep using it and report back if there are any more issues. Thank you so much!

dpo avatar Apr 02 '23 22:04 dpo

You're welcome. I don't know why the arm64 has an issue, it's my usual build system

philippe44 avatar Apr 02 '23 22:04 philippe44

Bad news. I'm back to the same place. This morning, I could not connect from either macOS or iOS. I unloaded and reloaded the service. I can connect from macOS, but not from iOS. The behavior is the same if I launch from the command line. However, typing exit exits cleanly.

As in my original message, a failed connection from iOS makes it impossible to connect from macOS afterwards.

Perhaps it has something to do with going to and waking from sleep?

Log: https://gist.github.com/dpo/b2797102be125fa1dcc922a6c958b332

dpo avatar Apr 03 '23 16:04 dpo

It's not a log

philippe44 avatar Apr 07 '23 05:04 philippe44

Apologies. Here's a log: https://gist.github.com/dpo/f6552c6bf8b5f1b684d6f28fc4f7878e

Today I could connect from macOS, but not from iOS. The playbacks in the log file are from macOS. There was no successful connection from iOS. Please let me know what else I can provide to make debugging easier.

dpo avatar Apr 10 '23 17:04 dpo

I just tested the latest releases (both arm4 and x86_64). They both work fine on the Mac. I'm still unable to connect to my older Sonos Amp from iOS, but at least attempting to connect no longer blocks access for the Mac.

dpo avatar May 02 '23 21:05 dpo