open62541 / open62541

Open source implementation of OPC UA (OPC Unified Architecture) aka IEC 62541 licensed under Mozilla Public License v2.0
http://open62541.org
Mozilla Public License 2.0
2.63k stars 1.25k forks source link

PubSub MQTT : port 8884. Mqtt_sync() works for the 1st pass, then it fails at the subsequent passes (openssl) #5005

Open jackybek opened 2 years ago

jackybek commented 2 years ago

Description

When i setup the system to send to port 8884, the mqtt_sync(client) function in yieldMqtt() works with no error for the very 1st time. However, the subsequent call to yieldMqtt() fails. See tracelog below:

This issue does not happen if i use port 1883 and 1884.

entering mqtt_pal_sendall() : len = 55 UA_ENABLE_MQTT_TLS = true and UA_ENABLE_MQTT_TLS_OPENSSL = true written = 0, len = 55 rv = SSL_write() = 55 out of UA_ENABLE_MQTT_TLS_OPENSSL segment mqtt_pal_sendall() : sendBuffer.data = ▒, len = 55 mqtt_pal_sendall() : checking the status after calling connection->send() function :: 0 Good this should not be -1, should get 55 : tmp = 55 advancing to here 1 (in mqtt_send()) advancing to here 2 (in __mqtt_send()) advancing to here 3 (in mqtt_send()) leaving __mqtt_send() with no errors yieldMqtt() : mqtt_sync() returns 0x1 yieldMqtt() : mqtt_sync() returns 0x80000011 [2022-03-13 16:57:56.380 (UTC+0800)] error/server PubSub MQTT: yield: error: MQTT_ERROR_SOCKET_ERROR [2022-03-13 16:58:08.327 (UTC+0800)] warn/server PubSub MQTT: sending failed. Invalid state.

Background Information / Reproduction Steps

Used CMake options:

CMake Warning: No source or binary directory provided. Both will be assumed to be the same as the current working directory, but note that this warning will become a fatal error in future CMake releases.

CMake Error: The source directory "/home/pi/open62541/build" does not appear to contain CMakeLists.txt. Specify --help for usage, or press the help button on the CMake GUI. -- Cache values BIBER_COMPILER:FILEPATH=BIBER_COMPILER-NOTFOUND BIBTEX_COMPILER:FILEPATH=BIBTEX_COMPILER-NOTFOUND BUILD_SHARED_LIBS:BOOL=OFF CLANG_FORMAT_EXE:FILEPATH=CLANG_FORMAT_EXE-NOTFOUND CLANG_FORMAT_PROGRAM:FILEPATH=CLANG_FORMAT_PROGRAM-NOTFOUND CLANG_TIDY_PROGRAM:FILEPATH=CLANG_TIDY_PROGRAM-NOTFOUND CMAKE_ADDR2LINE:FILEPATH=/usr/bin/addr2line CMAKE_AR:FILEPATH=/usr/bin/ar CMAKE_BUILD_TYPE:STRING=Debug CMAKE_COLOR_MAKEFILE:BOOL=ON CMAKE_C_COMPILER:FILEPATH=/usr/bin/cc CMAKE_C_COMPILER_AR:FILEPATH=/usr/bin/gcc-ar-8 CMAKE_C_COMPILER_RANLIB:FILEPATH=/usr/bin/gcc-ranlib-8 CMAKE_C_FLAGS:STRING= CMAKE_C_FLAGS_DEBUG:STRING=-g CMAKE_C_FLAGS_MINSIZEREL:STRING=-Os -DNDEBUG CMAKE_C_FLAGS_RELEASE:STRING=-O3 -DNDEBUG CMAKE_C_FLAGS_RELWITHDEBINFO:STRING=-O2 -g -DNDEBUG CMAKE_DLLTOOL:FILEPATH=CMAKE_DLLTOOL-NOTFOUND CMAKE_EXE_LINKER_FLAGS:STRING= CMAKE_EXE_LINKER_FLAGS_DEBUG:STRING= CMAKE_EXE_LINKER_FLAGS_MINSIZEREL:STRING= CMAKE_EXE_LINKER_FLAGS_RELEASE:STRING= CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO:STRING= CMAKE_EXPORT_COMPILE_COMMANDS:BOOL=OFF CMAKE_INSTALL_BINDIR:PATH=bin CMAKE_INSTALL_DATADIR:PATH= CMAKE_INSTALL_DATAROOTDIR:PATH=share CMAKE_INSTALL_DOCDIR:PATH= CMAKE_INSTALL_INCLUDEDIR:PATH=include CMAKE_INSTALL_INFODIR:PATH= CMAKE_INSTALL_LIBDIR:PATH=lib CMAKE_INSTALL_LIBEXECDIR:PATH=libexec CMAKE_INSTALL_LOCALEDIR:PATH= CMAKE_INSTALL_LOCALSTATEDIR:PATH=var CMAKE_INSTALL_MANDIR:PATH= CMAKE_INSTALL_OLDINCLUDEDIR:PATH=/usr/include CMAKE_INSTALL_PREFIX:PATH=/usr/local CMAKE_INSTALL_RUNSTATEDIR:PATH= CMAKE_INSTALL_SBINDIR:PATH=sbin CMAKE_INSTALL_SHAREDSTATEDIR:PATH=com CMAKE_INSTALL_SYSCONFDIR:PATH=etc CMAKE_LINKER:FILEPATH=/usr/bin/ld CMAKE_MAKE_PROGRAM:FILEPATH=/usr/bin/make CMAKE_MODULE_LINKER_FLAGS:STRING= CMAKE_MODULE_LINKER_FLAGS_DEBUG:STRING= CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL:STRING= CMAKE_MODULE_LINKER_FLAGS_RELEASE:STRING= CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO:STRING= CMAKE_NM:FILEPATH=/usr/bin/nm CMAKE_OBJCOPY:FILEPATH=/usr/bin/objcopy CMAKE_OBJDUMP:FILEPATH=/usr/bin/objdump CMAKE_RANLIB:FILEPATH=/usr/bin/ranlib CMAKE_READELF:FILEPATH=/usr/bin/readelf CMAKE_SHARED_LINKER_FLAGS:STRING= CMAKE_SHARED_LINKER_FLAGS_DEBUG:STRING= CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL:STRING= CMAKE_SHARED_LINKER_FLAGS_RELEASE:STRING= CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO:STRING= CMAKE_SKIP_INSTALL_RPATH:BOOL=NO CMAKE_SKIP_RPATH:BOOL=NO CMAKE_STATIC_LINKER_FLAGS:STRING= CMAKE_STATIC_LINKER_FLAGS_DEBUG:STRING= CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL:STRING= CMAKE_STATIC_LINKER_FLAGS_RELEASE:STRING= CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO:STRING= CMAKE_STRIP:FILEPATH=/usr/bin/strip CMAKE_VERBOSE_MAKEFILE:BOOL=FALSE CPACK_SOURCE_RPM:BOOL=OFF CPACK_SOURCE_TBZ2:BOOL=ON CPACK_SOURCE_TGZ:BOOL=ON CPACK_SOURCE_TXZ:BOOL=ON CPACK_SOURCE_TZ:BOOL=ON CPACK_SOURCE_ZIP:BOOL=OFF DVIPDF_CONVERTER:FILEPATH=/usr/bin/dvipdf DVIPS_CONVERTER:FILEPATH=DVIPS_CONVERTER-NOTFOUND GIT_EXECUTABLE:FILEPATH=/usr/bin/git HTLATEX_COMPILER:FILEPATH=HTLATEX_COMPILER-NOTFOUND LATEX2HTML_CONVERTER:FILEPATH=LATEX2HTML_CONVERTER-NOTFOUND LATEX_COMPILER:FILEPATH=LATEX_COMPILER-NOTFOUND LIBWEBSOCKETS_INCLUDE_DIR:PATH=/usr/local/include LIBWEBSOCKETS_LIBRARIES:FILEPATH=/usr/local/lib/libwebsockets.so LIB_BPF:FILEPATH=LIB_BPF-NOTFOUND LUALATEX_COMPILER:FILEPATH=LUALATEX_COMPILER-NOTFOUND MAKEINDEX_COMPILER:FILEPATH=MAKEINDEX_COMPILER-NOTFOUND MBEDCRYPTO_LIBRARY:FILEPATH=/usr/lib/arm-linux-gnueabihf/libmbedcrypto.so MBEDTLS_INCLUDE_DIRS:PATH=/usr/include MBEDTLS_LIBRARY:FILEPATH=/usr/lib/arm-linux-gnueabihf/libmbedtls.so MBEDX509_LIBRARY:FILEPATH=/usr/lib/arm-linux-gnueabihf/libmbedx509.so MDNSD_LOGLEVEL:STRING=300 OPENSSL_CRYPTO_LIBRARY:FILEPATH=/usr/local/ssl/lib/libcrypto.so OPENSSL_INCLUDE_DIR:PATH=/usr/local/ssl/include OPENSSL_SSL_LIBRARY:FILEPATH=/usr/local/ssl/lib/libssl.so PDFLATEX_COMPILER:FILEPATH=PDFLATEX_COMPILER-NOTFOUND PDFTOPS_CONVERTER:FILEPATH=/usr/bin/pdftops PKG_CONFIG_EXECUTABLE:FILEPATH=/usr/bin/pkg-config PS2PDF_CONVERTER:FILEPATH=/usr/bin/ps2pdf14 Python3_EXECUTABLE:FILEPATH=/usr/bin/python3.7 SPHINX_EXECUTABLE:FILEPATH=SPHINX_EXECUTABLE-NOTFOUND UA_AMALGAMATION_ARCHITECTURES:STRING= UA_ARCHITECTURE:STRING=posix UA_ARCH_ADD_FLAGS:STRING= UA_ARCH_EXTRA_INCLUDES:STRING= UA_ARCH_LINKER_FLAGS:STRING= UA_ARCH_REMOVE_FLAGS:STRING= UA_BUILD_EXAMPLES:BOOL=OFF UA_BUILD_FUZZING:BOOL=OFF UA_BUILD_FUZZING_CORPUS:BOOL=OFF UA_BUILD_OSS_FUZZ:BOOL=OFF UA_BUILD_TOOLS:BOOL=OFF UA_BUILD_UNIT_TESTS:BOOL=OFF UA_DEBUG:BOOL=OFF UA_DEBUG_DUMP_PKGS:BOOL=OFF UA_DEBUG_FILE_LINE_INFO:BOOL=OFF UA_ENABLE_AMALGAMATION:BOOL=ON UA_ENABLE_CLANG_COV:BOOL=OFF UA_ENABLE_COVERAGE:BOOL=OFF UA_ENABLE_DA:BOOL=ON UA_ENABLE_DETERMINISTIC_RNG:BOOL=OFF UA_ENABLE_DIAGNOSTICS:BOOL=OFF UA_ENABLE_DISCOVERY:BOOL=ON UA_ENABLE_DISCOVERY_MULTICAST:BOOL=ON UA_ENABLE_DISCOVERY_SEMAPHORE:BOOL=ON UA_ENABLE_ENCRYPTION:STRING=OPENSSL UA_ENABLE_ENCRYPTION_MBEDTLS:BOOL=OFF UA_ENABLE_ENCRYPTION_OPENSSL:BOOL=ON UA_ENABLE_ENCRYPTION_TPM2:STRING=OFF UA_ENABLE_EXPERIMENTAL_HISTORIZING:BOOL=OFF UA_ENABLE_HARDENING:BOOL=ON UA_ENABLE_HISTORIZING:BOOL=ON UA_ENABLE_IMMUTABLE_NODES:BOOL=OFF UA_ENABLE_JSON_ENCODING:BOOL=ON UA_ENABLE_MALLOC_SINGLETON:BOOL=OFF UA_ENABLE_METHODCALLS:BOOL=ON UA_ENABLE_MQTT_TLS:BOOL=ON UA_ENABLE_MQTT_TLS_OPENSSL:BOOL=ON UA_ENABLE_NODEMANAGEMENT:BOOL=ON UA_ENABLE_NODESET_COMPILER_DESCRIPTIONS:BOOL=ON UA_ENABLE_PARSING:BOOL=ON UA_ENABLE_PUBSUB:BOOL=ON UA_ENABLE_PUBSUB_BUFMALLOC:BOOL=OFF UA_ENABLE_PUBSUB_DELTAFRAMES:BOOL=ON UA_ENABLE_PUBSUB_ENCRYPTION:BOOL=ON UA_ENABLE_PUBSUB_ETH_UADP:BOOL=ON UA_ENABLE_PUBSUB_FILE_CONFIG:BOOL=OFF UA_ENABLE_PUBSUB_INFORMATIONMODEL:BOOL=ON UA_ENABLE_PUBSUB_INFORMATIONMODEL_METHODS:BOOL=ON UA_ENABLE_PUBSUB_MONITORING:BOOL=ON UA_ENABLE_PUBSUB_MQTT:BOOL=ON UA_ENABLE_QUERY:BOOL=OFF UA_ENABLE_STATIC_ANALYZER:STRING=OFF UA_ENABLE_STATUSCODE_DESCRIPTIONS:BOOL=ON UA_ENABLE_SUBSCRIPTIONS:BOOL=ON UA_ENABLE_SUBSCRIPTIONS_ALARMS_CONDITIONS:BOOL=ON UA_ENABLE_SUBSCRIPTIONS_EVENTS:BOOL=ON UA_ENABLE_TYPEDESCRIPTION:BOOL=ON UA_ENABLE_UNIT_TESTS_MEMCHECK:BOOL=OFF UA_ENABLE_UNIT_TEST_FAILURE_HOOKS:BOOL=OFF UA_ENABLE_VALGRIND_INTERACTIVE:BOOL=OFF UA_ENABLE_WEBSOCKET_SERVER:BOOL=ON UA_FILE_NS0:BOOL=OFF UA_FILE_NS0_BLACKLIST:BOOL=OFF UA_FORCE_32BIT:BOOL=OFF UA_FORCE_CPP:BOOL=OFF UA_FORCE_WERROR:BOOL=ON UA_LOGLEVEL:STRING=300 UA_MSVC_FORCE_STATIC_CRT:BOOL=ON UA_MULTITHREADING:STRING=0 UA_NAMESPACE_ZERO:STRING=FULL UA_PACK_DEBIAN:BOOL=OFF UA_VALGRIND_INTERACTIVE_INTERVAL:STRING=1000 XELATEX_COMPILER:FILEPATH=XELATEX_COMPILER-NOTFOUND XINDY_COMPILER:FILEPATH=XINDY_COMPILER-NOTFOUND pkgcfg_libOPENSSL_crypto:FILEPATH=/usr/local/lib/libcrypto.so pkgcfg_libOPENSSL_ssl:FILEPATH=/usr/local/lib/libssl.so

cmake -DUA_NAMESPACE_ZERO=<YOUR_OPTION> <ANY_OTHER_OPTIONS> ..

Checklist

Please provide the following information:

jackybek commented 2 years ago

i trace the code and found that

  1. in TransportLayerMQTT_addChannel(), it calls TransportLayerMQTT_addChannel()
  2. in UA_PubSubChannelMQTT_open(), the channel->state is set to UA_PUBSUB_CHANNEL_RDY
  3. following code in TransportLayerMQTT_addChannel() sets channel->state = UA_PUBSUB_CHANNEL_RDY for the very first time it is called.

if(pubSubChannel){ pubSubChannel->regist = UA_PubSubChannelMQTT_regist; pubSubChannel->unregist = UA_PubSubChannelMQTT_unregist; pubSubChannel->send = UA_PubSubChannelMQTT_send; pubSubChannel->close = UA_PubSubChannelMQTT_close; pubSubChannel->yield = UA_PubSubChannelMQTT_yield; pubSubChannel->connectionConfig = connectionConfig; }

Subsequent calls to UA_PubSubChannelMQTT_yield also set channel->state = UA_PUBSUB_CHANNEL_RDY But when the function UA_PubSubChannelMQTT_send() is called now, channel->state becomes UA_PUBSUB_CHANNEL_ERROR