Mosquitto builds ok with the option to support websockets and apparently initiates the listener, however no client can connect using websockets, log doesn't show any errors (below): LOG FILE 2022-03-15T10:29:21: mosquitto version 2.0.13 starting 2022-03-15T10:29:21: Config loaded from /usr/local/etc/mosquitto/mosquitto.conf. 2022-03-15T10:29:21: Loading plugin: /usr/local/lib/mosquitto_dynamic_security.so 2022-03-15T10:29:21: Opening ipv6 listen socket on port 8666. 2022-03-15T10:29:21: Opening ipv4 listen socket on port 8666. 2022-03-15T10:29:21: Opening websockets listen socket on port 8667. 2022-03-15T10:29:21: mosquitto version 2.0.13 running NETSTAT Active Internet connections (including servers) Proto Recv-Q Send-Q Local Address Foreign Address (state) tcp4 0 0 10.0.0.33.8666 10.0.0.5.59398 ESTABLISHED tcp6 0 0 *.8667 *.* LISTEN tcp4 0 0 *.8666 *.* LISTEN tcp6 0 0 *.8666 *.* LISTEN tcp4 0 0 *.* *.* CLOSED Same configuration files works flawlessly on Linux.
Hi! I'd recommend filling a bug report with Mosquitto project, and then updating this report with a link to the bug report. Best regards, -Joe
(In reply to joe from comment #1) I'm not sure I understand what did you mean. Are you suggesting that I raise a bug on Eclipse/mosquitto github repo?
Greetings. It appears that the port of net/mosquitto under FreeBSD 13.0-RELEASE on arm64 (Raspberry Pi) does not support Websockets. See message I get when I try to start: joji@nirmal> sudo service mosquitto onestart Starting mosquitto. 1647444243: Error: Websockets support not available. 1647444243: Error found at /usr/local/etc/mosquitto/mosquitto.conf:284. /usr/local/etc/rc.d/mosquitto: WARNING: failed to start mosquitto Is the reason Websockets support is not available in the port and the OP being not able to get it working, despite fresh compile related to an upstream issue (and hence the port maintainer suggesting opening bug report with Eclipse)? If so, it would be helpful to know what the issue in the upstream code is. Thank you. joseph
(In reply to Joseph from comment #3) Is the installed version from the freebsd pkg repo? This Version seems to have Websockets disabled per Default. WS=off: MQTT over Websockets support If thats the Case you should compile the port with non default options to enable this. If this Option is suitable for most users the maintainer may set this as default option.
(In reply to Henrik Rosenke from comment #4) Yes, the installed version is the freebsd pkg repo. And yes, I'll try compiling from source with Websockets enabled. Hopefully, I won't run into the same issue as OP. I was hoping to find out from the maintainer of the port if there was a specific upstream bug or some such that prevented default support for Websockets in the port in the pkg repo.
(In reply to Joseph from comment #5) ---UPDATE--- I rebuilt mosquitto and libwebsockets (with LWS_WITH_EXTERNAL_POLL support) and upon testing, the client/subscriber appears to be unable to keep a connection open to the broker. It is closing connection immediately. See transcript below. The client appears to be retrying every 2 seconds. I specified a "keepalive=300" value to the connect call, but it did not seem to make a difference. Works fine when using mqtt protocol. So, looks like the libwebsockets portion is broken on FreeBSD. I tested on OpenBSD and websockets works fine there. However, the versions there are: libwebsockets-2.4.2 and mosquitto-2.0.12. [ Transcript from /var/log/daemon.log ] Mar 17 13:09:22 nirmal mosquitto[6450]: 1647536962: New client connected from 192.168.50.210:25231 as wallace-client (p2, c1, k300, u'wallace'). Mar 17 13:09:22 nirmal mosquitto[6450]: 1647536962: Client wallace-client closed its connection. Mar 17 13:09:24 nirmal mosquitto[6450]: 1647536964: New client connected from 192.168.50.210:23099 as wallace-client (p2, c1, k300, u'wallace'). Mar 17 13:09:24 nirmal mosquitto[6450]: 1647536964: Client wallace-client closed its connection. Mar 17 13:09:26 nirmal mosquitto[6450]: 1647536966: New client connected from 192.168.50.210:3 001 as wallace-client (p2, c1, k300, u'wallace'). Mar 17 13:09:26 nirmal mosquitto[6450]: 1647536966: Client wallace-client closed its connection. [...] Mar 17 13:15:32 nirmal mosquitto[6450]: 1647537332: New client connected from 192.168.50.210:9553 as wallace-client (p2, c1, k300, u'wallace'). Mar 17 13:15:32 nirmal mosquitto[6450]: 1647537332: Client wallace-client closed its connection.
You might also want to try updating libwebsockets as upstream is at 4.3.1 and the port is still at 4.2.2
This issue still exists with the update to mosquitto 2.0.15. libwebsockets is still at 4.2.2 and the port has no maintainer. This issue appears to be limited to websockets support. MQTT works without issues. I have built both mosquitto and libwebsockets from their ports. Mosquitto with support for websockets and libwebsockets with support for MQTT.
Created attachment 240117 [details] Patch for libwebsockets Update libwebsockets to 4.3.2
(In reply to Rod Morgan from comment #8) Can you give it a try to 4.3.2 (patch attached) ?
Applied patch to libwebsockets. Cleaned, then rebuilt both libwebsockets and mosquitto from ports. Same problem, websockets not working. Feb 12 15:20:15 blanca mosquitto[96842]: 1676240415: mosquitto version 2.0.15 starting Feb 12 15:20:15 blanca mosquitto[96842]: 1676240415: Config loaded from mosquitto.conf. Feb 12 15:20:15 blanca mosquitto[96842]: 1676240415: Opening ipv4 listen socket on port 1883. Feb 12 15:20:15 blanca mosquitto[96842]: 1676240415: Opening ipv4 listen socket on port 8080. Feb 12 15:20:15 blanca mosquitto[96842]: 1676240415: mosquitto version 2.0.15 running The log file should show: Feb 12 15:20:15 blanca mosquitto[96842]: 1676240723: Opening ipv4 listen socket on port 1883. Feb 12 15:20:15 blanca mosquitto[96842]: 1676240723: Opening websockets listen socket on port 8080. Watching the build readout I see the following warning (which directly addresses my issue). warning "libwebsockets is not compiled with LWS_WITH_EXTERNAL_POLL support. Websocket performance will be unusable."
Add LWS_WITH_EXTERNAL_POLL to CMAKE_ON (Line 23, https://cgit.freebsd.org/ports/tree/net/libwebsockets/Makefile#n23) and recompile libwebsockets + mosquitto
Done...no warnings when building, but no joy: log output Feb 12 16:29:51 blanca mosquitto[10366]: 1676244591: mosquitto version 2.0.15 starting Feb 12 16:29:51 blanca mosquitto[10366]: 1676244591: Config loaded from mosquitto.conf. Feb 12 16:29:51 blanca mosquitto[10366]: 1676244591: Opening ipv4 listen socket on port 1883. Feb 12 16:29:51 blanca mosquitto[10366]: 1676244591: Opening ipv4 listen socket on port 8080. Feb 12 16:29:51 blanca mosquitto[10366]: 1676244591: mosquitto version 2.0.15 running Same as before.
Created attachment 240125 [details] Patch for libwebsockets v3 Sync defaults with other repos and upstream recommendations Enable LWS_WITH_DISKCACHE, LWS_WITH_FTS, LWS_WITH_RANGES, LWS_WITH_THREADPOOL and (LWS_WITH_EXTERNAL_POLL via MQTT option) Use SHA1 via OpenSSL (LWS_WITHOUT_BUILTIN_SHA1)
(In reply to Rod Morgan from comment #13) Hmm... I guess you could give v3 a try but I'm not a user so this is a bit of a guess that "might" fix it. I see that some distros also define LWS_WITHOUT_BUILTIN_GETIFADDRS however according do upstream this should error out if its an issue during build. Also, 2.X doesn't support anonymous connections by default (you need to define allow_anonymous true) but I would assume that it would at least connect and error out...
First and foremost, thanks for looking into this. Looking at your patch file, it appears to be a patch to the original libwebsockets v4.2.2. Assuming that to be correct, I restored the libwebsockets port to its original state (prior to the first patch). Implemented the new patch to v4.3.2, deinstalled, cleaned, config'd, installed. All with no errors or warnings. Upon rebuilding (deinstall, clean, install) mosquitto, I got a failure referencing an undefined symbol for pthread_create. I've attached the patched libwebsockets Makefile and the mosquitto make error. Here is the v4.3.2 Makefile. ======= PORTNAME= libwebsockets DISTVERSIONPREFIX= v DISTVERSION= 4.3.2 CATEGORIES= net devel MASTER_SITES= https://libwebsockets.org/git/libwebsockets/snapshot/ MAINTAINER= ports@FreeBSD.org COMMENT= C library for lightweight websocket clients and servers WWW= https://libwebsockets.org/ LICENSE= MIT LICENSE_FILE= ${WRKSRC}/LICENSE USES= cmake localbase pkgconfig tar:xz USE_LDCONFIG= yes BUILDINFO= ${HOSTARCH}-portbld-${OPSYS:tl}-${OSREL:R} CMAKE_ARGS= -DLWS_BUILD_HASH:STRING="${BUILDINFO}" CMAKE_ON= CMAKE_DISABLE_FIND_PACKAGE_Git \ LWS_WITH_DISKCACHE LWS_WITH_FTS LWS_IPV6 LWS_WITH_RANGES \ LWS_WITH_SSL LWS_WITH_THREADPOOL LWS_WITH_ZLIB \ LWS_WITHOUT_BUILTIN_SHA1 \ LWS_WITHOUT_TESTAPPS LWS_WITHOUT_TEST_SERVER \ LWS_WITHOUT_TEST_SERVER_EXTPOLL \ LWS_WITHOUT_TEST_PING LWS_WITHOUT_TEST_CLIENT OPTIONS_DEFINE= HTTP_PROXY HTTP2 MQTT PEERLIMITS PLUGINS \ SECURE_STREAMS SOCKS SQLITE WEBSERVER OPTIONS_DEFAULT= HTTP2 MQTT OPENSSL LIBUV OPTIONS_SUB= yes OPTIONS_SINGLE= SSL OPTIONS_SINGLE_SSL= MBEDTLS OPENSSL OPTIONS_GROUP= EVLOOP OPTIONS_GROUP_EVLOOP= GLIB LIBEV LIBEVENT LIBUV HTTP_PROXY_DESC= HTTP proxy support MQTT_DESC= MQTT client support PEERLIMITS_DESC= Tracking and limiting of resources of peer(s) PLUGINS_DESC= Plugins support SECURE_STREAMS_DESC= Secure streams protocol API support SOCKS_DESC= Allow use of SOCKS5 proxy on client connections EVLOOP_DESC= Event loop support GLIB_DESC= Events support via Glib LIBEVENT_DESC= Asynchronous event notification via libevent LIBUV_DESC= Asynchronous I/O support via libuv HTTP_PROXY_CMAKE_BOOL= LWS_WITH_HTTP_PROXY HTTP2_CMAKE_BOOL= LWS_WITH_HTTP2 MQTT_CMAKE_BOOL= LWS_ROLE_MQTT LWS_WITH_EXTERNAL_POLL PEERLIMITS_CMAKE_BOOL= LWS_WITH_PEER_LIMITS PLUGINS_CMAKE_BOOL= LWS_WITH_PLUGINS \ LWS_WITH_PLUGINS_API SECURE_STREAMS_CMAKE_BOOL= LWS_WITH_SECURE_STREAMS \ LWS_WITH_SECURE_STREAMS_PROXY_API SOCKS_CMAKE_BOOL= LWS_WITH_SOCKS5 SQLITE_LIB_DEPENDS= libsqlite3.so:databases/sqlite3 SQLITE_CMAKE_BOOL= LWS_WITH_SQLITE3 WEBSERVER_CMAKE_BOOL= LWS_WITH_LWSWS WEBSERVER_IMPLIES= PEERLIMITS PLUGINS LIBUV MBEDTLS_LIB_DEPENDS= libmbedtls.so:security/mbedtls MBEDTLS_CMAKE_BOOL= LWS_WITH_MBEDTLS OPENSSL_USES= ssl OPENSSL_CMAKE_BOOL= LWS_WITHOUT_BUILTIN_SHA1 # WolfSSL needs to be compiled with --enable-libwebsockets to work # WOLFSSL_LIB_DEPENDS= libwolfssl.so:security/wolfssl # WOLFSSL_CMAKE_BOOL= LWS_WITH_SSL LWS_WITH_WOLFSSL # WOLFSSL_CMAKE_ON= -DLWS_WOLFSSL_INCLUDE_DIRS=${LOCALBASE}/include \ # -DLWS_WOLFSSL_LIBRARIES=${LOCALBASE}/lib/libwolfssl.so GLIB_USES= gnome GLIB_USE= GNOME=glib20 GLIB_CMAKE_BOOL= LWS_WITH_GLIB LIBEV_LIB_DEPENDS= libev.so:devel/libev LIBEV_CMAKE_BOOL= LWS_WITH_LIBEV LIBEVENT_LIB_DEPENDS= libevent.so:devel/libevent LIBEVENT_CMAKE_BOOL= LWS_WITH_LIBEVENT LIBUV_LIB_DEPENDS= libuv.so:devel/libuv LIBUV_CMAKE_BOOL= LWS_WITH_LIBUV .include <bsd.port.options.mk> # Allow usage of LibreSSL via OPENSSL option .if ${PORT_OPTIONS:MOPENSSL} && ${SSL_DEFAULT} == libressl CMAKE_ARGS+= -DLWS_OPENSSL_LIBRARIES='${OPENSSLLIB}/libtls.so;${OPENSSLLIB}/libssl.so;${OPENSSLLIB}/libcrypto.so' -DLWS_OPENSSL_INCLUDE_DIRS=${OPENSSLINC}/ssl .endif .include <bsd.port.mk> ========= ========= FAILED: src/mosquitto : && /usr/bin/cc -O2 -pipe -fstack-protector-strong -fno-strict-aliasing -O2 -pipe -fstack-protector-strong -fno-strict-aliasing -DNDEBUG -fstack-protector-strong -Wl,-dynamic-list=/usr/ports/net/mosquitto/work/mosquitto-2.0.15/src/linker.syms src/CMakeFiles/mosquitto.dir/__/lib/alias_mosq.c.o src/CMakeFiles/mosquitto.dir/bridge.c.o src/CMakeFiles/mosquitto.dir/bridge_topic.c.o src/CMakeFiles/mosquitto.dir/conf.c.o src/CMakeFiles/mosquitto.dir/conf_includedir.c.o src/CMakeFiles/mosquitto.dir/context.c.o src/CMakeFiles/mosquitto.dir/control.c.o src/CMakeFiles/mosquitto.dir/database.c.o src/CMakeFiles/mosquitto.dir/handle_auth.c.o src/CMakeFiles/mosquitto.dir/handle_connack.c.o src/CMakeFiles/mosquitto.dir/handle_connect.c.o src/CMakeFiles/mosquitto.dir/handle_disconnect.c.o src/CMakeFiles/mosquitto.dir/__/lib/handle_ping.c.o src/CMakeFiles/mosquitto.dir/__/lib/handle_pubackcomp.c.o src/CMakeFiles/mosquitto.dir/handle_publish.c.o src/CMakeFiles/mosquitto.dir/__/lib/handle_pubrec.c.o src/CMakeFiles/mosquitto.dir/__/lib/handle_pubrel.c.o src/CMakeFiles/mosquitto.dir/__/lib/handle_suback.c.o src/CMakeFiles/mosquitto.dir/handle_subscribe.c.o src/CMakeFiles/mosquitto.dir/__/lib/handle_unsuback.c.o src/CMakeFiles/mosquitto.dir/handle_unsubscribe.c.o src/CMakeFiles/mosquitto.dir/keepalive.c.o src/CMakeFiles/mosquitto.dir/logging.c.o src/CMakeFiles/mosquitto.dir/loop.c.o src/CMakeFiles/mosquitto.dir/__/lib/memory_mosq.c.o src/CMakeFiles/mosquitto.dir/memory_public.c.o src/CMakeFiles/mosquitto.dir/mosquitto.c.o src/CMakeFiles/mosquitto.dir/__/lib/misc_mosq.c.o src/CMakeFiles/mosquitto.dir/mux.c.o src/CMakeFiles/mosquitto.dir/mux_epoll.c.o src/CMakeFiles/mosquitto.dir/mux_poll.c.o src/CMakeFiles/mosquitto.dir/net.c.o src/CMakeFiles/mosquitto.dir/__/lib/net_mosq_ocsp.c.o src/CMakeFiles/mosquitto.dir/__/lib/net_mosq.c.o src/CMakeFiles/mosquitto.dir/__/lib/packet_datatypes.c.o src/CMakeFiles/mosquitto.dir/__/lib/packet_mosq.c.o src/CMakeFiles/mosquitto.dir/password_mosq.c.o src/CMakeFiles/mosquitto.dir/persist_read_v234.c.o src/CMakeFiles/mosquitto.dir/persist_read_v5.c.o src/CMakeFiles/mosquitto.dir/persist_read.c.o src/CMakeFiles/mosquitto.dir/persist_write_v5.c.o src/CMakeFiles/mosquitto.dir/persist_write.c.o src/CMakeFiles/mosquitto.dir/plugin.c.o src/CMakeFiles/mosquitto.dir/plugin_public.c.o src/CMakeFiles/mosquitto.dir/property_broker.c.o src/CMakeFiles/mosquitto.dir/__/lib/property_mosq.c.o src/CMakeFiles/mosquitto.dir/read_handle.c.o src/CMakeFiles/mosquitto.dir/retain.c.o src/CMakeFiles/mosquitto.dir/security.c.o src/CMakeFiles/mosquitto.dir/security_default.c.o src/CMakeFiles/mosquitto.dir/__/lib/send_mosq.c.o src/CMakeFiles/mosquitto.dir/send_auth.c.o src/CMakeFiles/mosquitto.dir/send_connack.c.o src/CMakeFiles/mosquitto.dir/__/lib/send_connect.c.o src/CMakeFiles/mosquitto.dir/__/lib/send_disconnect.c.o src/CMakeFiles/mosquitto.dir/__/lib/send_publish.c.o src/CMakeFiles/mosquitto.dir/send_suback.c.o src/CMakeFiles/mosquitto.dir/signals.c.o src/CMakeFiles/mosquitto.dir/__/lib/send_subscribe.c.o src/CMakeFiles/mosquitto.dir/send_unsuback.c.o src/CMakeFiles/mosquitto.dir/__/lib/send_unsubscribe.c.o src/CMakeFiles/mosquitto.dir/session_expiry.c.o src/CMakeFiles/mosquitto.dir/__/lib/strings_mosq.c.o src/CMakeFiles/mosquitto.dir/subs.c.o src/CMakeFiles/mosquitto.dir/sys_tree.c.o src/CMakeFiles/mosquitto.dir/__/lib/time_mosq.c.o src/CMakeFiles/mosquitto.dir/__/lib/tls_mosq.c.o src/CMakeFiles/mosquitto.dir/topic_tok.c.o src/CMakeFiles/mosquitto.dir/__/lib/util_mosq.c.o src/CMakeFiles/mosquitto.dir/__/lib/util_topic.c.o src/CMakeFiles/mosquitto.dir/__/lib/utf8_mosq.c.o src/CMakeFiles/mosquitto.dir/websockets.c.o src/CMakeFiles/mosquitto.dir/will_delay.c.o src/CMakeFiles/mosquitto.dir/__/lib/will_mosq.c.o -o src/mosquitto -L/usr/local/lib -Wl,-rpath,/usr/local/lib: -lssl -lcrypto -ldl -lm -lrt /usr/local/lib/libwebsockets.a -lssl -lcrypto -lz && : ld: error: undefined symbol: pthread_create >>> referenced by threadpool.c >>> threadpool.c.o:(lws_threadpool_create) in archive /usr/local/lib/libwebsockets.a ==============
(In reply to Rod Morgan from comment #16) You found another bug, appling patch in PR 269536 should fix that issue You're correct that v3 only applies to a "clean"/untouched tree
PR 269536 committed so you should be able to compile now once you update your ports tree and run make clean for mosquitto.
Daniel, again thanks for your work. As instructed, I updated my ports collection. Just to be on the safe side, I deinstalled/cleaned/installed v4.3.2 of libwebsockets. Then I deinstalled/cleaned/installed mosquitto. As expected, it compiled/linked without error this time. Unfortunately, still not getting websocket support. I've confirmed my mosquitto.conf file specifies use of websockets: listener 1883 0.0.0.0 protocol mqtt listener 8080 0.0.0.0 protocol websockets Unfortunately, running mosquitto from the command line (mosquitta -v -c mosquitto.conf) still doesn't show the expected log file message indicating an active websocket connection. Honestly, I'm not sure where to go from here. There doesn't seem to be any enhanced debug option for mosquitto, 1676345357: mosquitto version 2.0.15 starting 1676345357: Config loaded from mosquitto.conf. 1676345357: Opening ipv4 listen socket on port 1883. 1676345357: Opening ipv4 listen socket on port 8080. 1676345357: mosquitto version 2.0.15 running
Since mosquitto has limited debug information, I used log_printf statements hoping to find where the websocket was initialized. In websockets.c there is a case statement/condition for LWS_CALLBACK_ADD_POLL_FD that calls the function to add websocket listeners. I cannot find anywhere else in the code or Makefile where it is referenced. I'm reasonably certain that if the case condition is never defined, then the code within that case condition will never be executed. I have no experience using Makefile (much less patching it). I'm thinking LWS_CALLBACK_ADD_POLL_FD needs to be defined somewhere to enable the case option to be triggered.
Sorry, that's a red herring. LWS_CALLBACK_ADD_POLL_FD is defined/declared in libwebsockets. I'll keep debugging.
Good news, but a little bit embarrassing. After Daniel's patches to libwebsockets and to mosquitto, the port works as expected. I had caused some of my issues by having an extra 'protocol' entry in the mosquitto.conf. If you have "protocol mqtt" entry AFTER the "protocol websockets", it overwrites the "protocol websockets". The changes to libwebsockets were definitely needed, but I can't honestly say the patch to mosquitto was required. Regardless, it works and I appreciate the work Daniel did.
Cool, I'll commit v3 then! Many thanks for testing!
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/ports/commit/?id=7a57329645f1189d8708f3624f59cd6115c0c706 commit 7a57329645f1189d8708f3624f59cd6115c0c706 Author: Daniel Engberg <diizzy@FreeBSD.org> AuthorDate: 2023-02-16 06:32:10 +0000 Commit: Daniel Engberg <diizzy@FreeBSD.org> CommitDate: 2023-02-16 06:33:40 +0000 net/libwebsockets: Update to 4.3.2 Adjust configuration options to closer match other distributions and also upstream's recommendations. Mosquitto also requires LWS_WITH_EXTERNAL_POLL to be enabled when linked with this library. Enable following options: LWS_WITH_DISKCACHE, LWS_WITH_FTS, LWS_WITH_RANGES, LWS_WITH_THREADPOOL and (LWS_WITH_EXTERNAL_POLL via MQTT option). Use SHA1 via OpenSSL (LWS_WITHOUT_BUILTIN_SHA1) While at also adjust .cmake and .pc files to properly report version Changelog: https://github.com/warmcat/libwebsockets/blob/v4.3.0/changelog https://github.com/warmcat/libwebsockets/compare/v4.3.0...v4.3.2 PR: 262552 Reported by: Leo Schneider <ttkdroid@gmail.com> Tested by: Rod Morgan <rmorgan@portmorgan.com> net/libwebsockets/Makefile | 15 +++++---- net/libwebsockets/distinfo | 6 ++-- ...ake_libwebsockets-config-version.cmake.in (new) | 8 +++++ .../files/patch-lib_CMakeLists.txt (new) | 38 ++++++++++++++++++++++ net/libwebsockets/pkg-plist | 6 +++- 5 files changed, 62 insertions(+), 11 deletions(-)