owntone / owntone-server

Linux/FreeBSD DAAP (iTunes) and MPD audio server with support for AirPlay 1 and 2 speakers (multiroom), Apple Remote (and compatibles), Chromecast, Spotify and internet radio.
https://owntone.github.io/owntone-server
GNU General Public License v2.0
2.08k stars 234 forks source link

httpd fatal error - protocol wrong type for socket on MacOS #1644

Closed Zorg-Org closed 1 year ago

Zorg-Org commented 1 year ago

Hello! Thanks for this awesome project first and foremost. I have used it on Linux without issue, but am having a really hard time getting it to run (it builds and installs fine) on MacOS.

1) steps to reproduce and/or logging of the error:

[2023-08-29 10:59:29] [ LOG] misc: Could not create service 'httpd' with address (ANY), port 3689: Protocol wrong type for socket [2023-08-29 10:59:29] [FATAL] httpd: server = httpd_server_new(evbase, httpd_port, request_cb, NULL) returned NULL at line 1370

2) version of owntone:

3) Platform I've reproduced this on the following Macs:

4) Additional info I tried some troubleshooting via this ticket as this person had a similar issue with wrong socket type on Mac. I tried their solution using their attached owntone.conf (and modifying it slightly to match my environment), but same error. I've tried running Owntone as root, as owntone user (it exists and owns /var/cache, etc.), and as my normal user, sudo and non-elevated, all get the same error.

I have tried installing Owntone both with Macports and building from source without it. Both methods yield the same fatal error. I don't want to install Homebrew on the same systems as coexisting withe Macports isn't guaranteed to go well. I've attached the associated MacOS crash reports, as well as the owntone log (set to debug) and config file.

As a side note, I was able to build, install, and run Owntone on a Linux machine (AntiX 22 on Pentium 4 32-bit) without issues.

I'm about out of ideas, I'm not sure why MacOS seems to have this httpd issue. Any idea what might be causing it?

P.S. As an aside, this is an awesome project and I'm super stoked you have put my ancient P4 laptop to use with this (!). Thank you!

P.P.S. I was able to build and run your librespot-c on PowerPC MacOS 10.5, which is extremely handy because native Spotify support on Darwin-based PowerPC platform is non-existent. Your library is fantastic and thank you for that, too.

owntone-2023-08-29-000618.ips.log ppc_owntone.crash.log owntone.log owntone.conf.md

ejurgensen commented 1 year ago

Thanks for the encouraging words!

I don't have a mac, so that's always an obstacle, but perhaps the issue also produces on FreeBSD and then I should be able to fix it.

was able to build and run your librespot-c on PowerPC MacOS 10.5, which is extremely handy because native Spotify support on Darwin-based PowerPC platform is non-existent. Your library is fantastic and thank you for that, too.

Awesome! PowerPC is big endian, right? I couldn't test with that and there is a bunch of bitlevel stuff in the library, so fantastic if it's working. Out of curiosity, how are you using the library - I understand it's with something else than OwnTone?

Zorg-Org commented 1 year ago

PowerPC is an odd beast for sure. I am not a hardware specialist, but from what I understand the 64-bit variants (e.g. Apple's Moto/IBM G5 processors and later Power8 and Power ISA) come in both little- and big-endian depending on the model (and a lot of them can switch modes at runtime!). The G4 and older PowerPC chips default to 32-bit big-endian.

As for the library, I was originally simply trying to find an alternative to libspotify/librespot that wasn't Rust-based (Darwin PowerPC doesn't have a functioning Rust or Go tool chain, so anything for these "ancient" Apple machines pretty much has to be in C or Python). There's a fairly active "retro" PowerPC user base out there, and I think it is still growing spurred on by Apple's migration away from Intel, harkening back to the last arch change of PowerPC-->Intel (https://forums.macrumors.com/forums/powerpc-macs.145/ if you're interested in the Apple PPC community).

I was able to compile test1 and use it to at least login to Spotify (thanks for putting the raw TCP data as output, that is awesome), but need to do some more tinkering to make it usable for a real use case. Once I had librespot-c going, I happened to notice that you had another project called Owntone which used the library and thought I'd try it, too. You have already created a fantastic program in Owntone, so if I can get the run-time errors eliminated I'll just use it as-is. Else, will try to use your library to create a very, very lightweight Spotify client for Darwin 32-bit PowerPC.

Your project(s) are also likely of interest to folks with embedded systems that use PowerPC, such as the Nintendo Wii or certain NAS systems.

As for the issue at hand, I will try using the Homebrew method on a 10.5 Intel VM and see if I get any better results with that route. Thanks again!

ejurgensen commented 1 year ago

I couldn't reproduce with FreeBSD, so instead I will try if I can reproduce using the macos that Github actions has.

ejurgensen commented 1 year ago

I was able to reproduce now. Looks like the mac os socket() won't accept SOCK_NONBLOCK. Looks like a small fix, shouldn't take long.

Zorg-Org commented 1 year ago

Glad to hear it's a small fix, thank you for the quick response. FWIW I tried it on a MacOS 10.13 machine today with the same results.

ejurgensen commented 1 year ago

I made an attempt at a fix, it's in the branch called macos_bind1. I hope you can test it.

Zorg-Org commented 1 year ago

Can confirm that fixed the issue on both 10.5/ppc and 12.6 /x64. You have given the fans of PowerPC-era hardware a great gift being able to interface natively with Spotify again. I have to give credit where it is due, debugging software for a platform you don't have the ability to test with isn't easy, bravo and thanks so much!

On a semi-related topic, I created all of the necessary Macports definitions (i.e. Porftfiles) required for owntone and all dependencies to be built/installed from within Macports. Would it be OK with you if I submitted owntone to the official Macports repo for addition? If Macports accepts them, all one would need to do to get owntone on a Mac is 1.) install Macports 2.) run port install owntone, no manual steps required.

ejurgensen commented 1 year ago

Glad to hear it's fixed now. The fix is merged into master now. I will also try to adjust Github actions so that the testing includes run testing on macos. Hopefully that will prevent future issues like this.

Yes, you are very welcome to add OwnTone to macports. Now that macos is working I will make a new release, so maybe you can submit that. If it's included then please let me know so I can update the install instructions.

ejurgensen commented 1 year ago

I've now made a new release (28.8) with this fix and some other ones too