Redisson Unable to write command into connection - redisson

Using redisson 3.13.3 to connect to Redis, but some time an exception throwed, the stack is below, but we can't find the slot or the channel port in the vm.
Unable to write command into connection! Node source: NodeSource [slot=13580, addr=null, redisClient=null, redirect=null, entry=null], connection: RedisConnection#41548252 [redisClient=[addr=redis://xxx.xxxx.xxx.xxx:port], channel=[id: 0xdcc1059a, L:0.0.0.0/0.0.0.0:55134 ! R:/xxx.xxxx.xxx.xxx:port], currentCommand=CommandData [promise=RedissonPromise [promise=ImmediateEventExecutor$ImmediatePromise#174dc5ee(failure: java.util.concurrent.CancellationException)], command=(EVAL), params=[if redis.call('setnx', KEYS[6], ARGV[4]) == 0 then return -1;end;redis.call('expire', KEYS[6], ARGV[..., 6, task.srm.task.4353929913272631325_product04, redisson__timeout__set:{task.srm.task.4353929913272631325_product04}, redisson__idle__set:{task.srm.task.4353929913272631325_product04}, redisson_map_cache_expired:{task.srm.task.4353929913272631325_product04}, redisson__map_cache__last_access__set:{task.srm.task.4353929913272631325_product04}, redisson__execute_task_once_latch:{task.srm.task.4353929913272631325_product04}, 1606882813929, 100, ...], codec=org.redisson.client.codec.LongCodec]], command: (EVAL), params: [local value = redis.call('hget', KEYS[1], ARGV[2]); local expireDate = 92233720368547758; if value ~..., 5, task.srm.tep.usage-v1_product04, redisson__timeout__set:{task.srm.tep.usage-v1_product04}, redisson__idle__set:{task.srm.tep.usage-v1_product04}, redisson__map_cache__last_access__set:{task.srm.tep.usage-v1_product04}, {task.srm.tep.usage-v1_product04}:redisson_options, 1606925138829, PooledUnsafeDirectByteBuf(ridx: 0, widx: 38, cap: 256)] after 3 retry attempts

Related

Semaphore FreeRTOS. xQueueGenericSend assert failed

So I'm trying to adapt a CPP library for ESP-IDF/Arduino BLE control into ESP-IDF v5.0 but I'm getting some errors regarding Semaphore from FreeRTOS when waiting. This is most likerly due to some APIs changing between ESP-IDF 3.0 to 5.0 but since Im just learning FreeRTOS I got a bit lost with the error.
Some logs from the program before the crash:
I (2376) BLEClient: >> connect(a6:c0:82:01:17:72)
I (2386) : 119660
I (2386) BLEDevice: add conn_id: 0, GATT role: client
I (2386) FreeRTOS: Semaphore taking: name: RegEvt (0x3ffdb0d4), owner: <N/A> for connect
I (2396) FreeRTOS: Semaphore taken: name: RegEvt (0x3ffdb0d4), owner: connect
I (2406) : 119628
assert failed: xQueueGenericSend queue.c:837 (pxQueue->pcHead != ((void *)0) || pxQueue->u.xSemaphore.xMutexHolder == ((void *)0) || pxQueue->u.xSemaphore.xMutexHolder == xTaskGetCurrentTaskHandle())
The traceback:
Backtrace: 0x40081d1e:0x3ffdacb0 0x40090699:0x3ffdacd0 0x4009687d:0x3ffdacf0 0x40090e62:0x3ffdae10 0x400dc597:0x3ffdae50 0x400d94d9:0x3ffdae90 0x400da145:0x3ffdaf10 0x400e0226:0x3ffdaf60 0x400e0922:0x3ffdaf80 0x400f73fd:0x3ffdafc0 0x400f95ab:0x3ffdafe0
0x40081d1e: panic_abort at C:/Espressif/frameworks/esp-idf-v5.0/components/esp_system/panic.c:412
0x40090699: esp_system_abort at C:/Espressif/frameworks/esp-idf-v5.0/components/esp_system/esp_system.c:135
0x4009687d: __assert_func at C:/Espressif/frameworks/esp-idf-v5.0/components/newlib/assert.c:78
0x40090e62: xQueueGenericSend at C:/Espressif/frameworks/esp-idf-v5.0/components/freertos/FreeRTOS-Kernel/queue.c:828 (discriminator 2)
0x400dc597: FreeRTOS::Semaphore::give() at C:/Users/amng8/Sync/PROJECTS/PillCPP/components/BLE/FreeRTOS.cpp:107
0x400d94d9: BLEClient::gattClientEventHandler(esp_gattc_cb_event_t, unsigned char, esp_ble_gattc_cb_param_t*) at C:/Users/amng8/Sync/PROJECTS/PillCPP/components/BLE/BLEClient.cpp:233
0x400da145: BLEDevice::gattClientEventHandler(esp_gattc_cb_event_t, unsigned char, esp_ble_gattc_cb_param_t*) at C:/Users/amng8/Sync/PROJECTS/PillCPP/components/BLE/BLEDevice.cpp:163
0x400e0226: btc_gattc_cb_to_app at C:/Espressif/frameworks/esp-idf-v5.0/components/bt/host/bluedroid/btc/profile/std/gatt/btc_gattc.c:24
0x400e0922: btc_gattc_cb_handler at C:/Espressif/frameworks/esp-idf-v5.0/components/bt/host/bluedroid/btc/profile/std/gatt/btc_gattc.c:1002
0x400f73fd: btc_thread_handler at C:/Espressif/frameworks/esp-idf-v5.0/components/bt/common/btc/core/btc_task.c:207
ELF file SHA256: b8542ed11e07aba6
0x400f95ab: osi_thread_run at C:/Espressif/frameworks/esp-idf-v5.0/components/bt/common/osi/thread.c:165
The code in question is from the file BLEClient.cpp function bool BLEClient::connect(BLEAddress address, esp_ble_addr_type_t type):
/**
* #brief Connect to the partner (BLE Server).
* #param [in] address The address of the partner.
* #return True on success.
*/
bool BLEClient::connect(BLEAddress address, esp_ble_addr_type_t type) {
ESP_LOGI(LOG_TAG, ">> connect(%s)", address.toString().c_str());
// We need the connection handle that we get from registering the application. We register the app
// and then block on its completion. When the event has arrived, we will have the handle.
m_appId = BLEDevice::m_appId++;
BLEDevice::addPeerDevice(this, true, m_appId);
m_semaphoreRegEvt.take("connect");
// clearServices(); // we dont need to delete services since every client is unique?
esp_err_t errRc = ::esp_ble_gattc_app_register(m_appId);
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "esp_ble_gattc_app_register: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
return false;
}
m_semaphoreRegEvt.wait("connect");
m_peerAddress = address;
// Perform the open connection request against the target BLE Server.
m_semaphoreOpenEvt.take("connect");
errRc = ::esp_ble_gattc_open(
m_gattc_if,
*getPeerAddress().getNative(), // address
type, // Note: This was added on 2018-04-03 when the latest ESP-IDF was detected to have changed the signature.
1 // direct connection <-- maybe needs to be changed in case of direct indirect connection???
);
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "esp_ble_gattc_open: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
return false;
}
uint32_t rc = m_semaphoreOpenEvt.wait("connect"); // Wait for the connection to complete.
ESP_LOGD(LOG_TAG, "<< connect(), rc=%d", rc==ESP_GATT_OK);
return rc == ESP_GATT_OK;
} // connect
and what seems to be triggering the crash is the .wait("connect") command.
Once again I'm new to FreeRTOS and Semaphore and not sure what's useful or not to get help so if you need any more information please let me know.

MQTT: getting `E (200965) TRANS_SSL: ssl_poll_write select error 113, errno = Software caused connection abort, fd = 57`

I am collecting data that I push to Microsoft IoT Hub thru MQTT.
My code runs on an ESP32-based custom PCB.
Everything sounds good (I get the data on the cloud), but after some duration (usually after 5 to 15 minutes), I get the following error:
E (200965) TRANS_SSL: ssl_poll_write select error 113, errno = Software caused connection abort, fd = 57
As per my understanding, this tells me it was not able to get an acknowledgment from the recipient, right?
My logs are as follows:
b6611|β€”|πŸ“¦ IoT: 🟒 MQTT: event MQTT_EVENT_PUBLISHED (activity: 24)
b6611|β€”|πŸ“¦ IoT: 🟒 MQTT: event MQTT_EVENT_PUBLISHED (activity: 25)
b6611|β€”|πŸ“¦ IoT: ==MQTT==: connected
(2)b6611|β€”|πŸ“¦ IoT: 🟒 WiFi connected
b6611|β€”|πŸ“¦ IoT: 🟒 SAS token not expired
b6611|β€”|πŸ“¦ IoT: 🟒 MQTT connected
b6611|β€”|πŸ“¦ IoT: 🟒 MQTT: event MQTT_EVENT_PUBLISHED (activity: 26)
E (200965) TRANS_SSL: ssl_poll_write select error 113, errno = Software caused connection abort, fd = 57
b6611|β€”|πŸ“¦ IoT: πŸ”΄ MQTT: event MQTT_EVENT_ERROR
E (200970) MQTT_CLIENT: Error write data or timeout, written len = -1, errno=0
E (200977) MQTT_CLIENT: Error to resend data
b6611|β€”|πŸ“¦ IoT: 🟑 MQTT: event MQTT_EVENT_DISCONNECTED
b6611|β€”|πŸ“¦ IoT: πŸ”΄ ==MQTT==: disconnected!
(0)b6611|β€”|πŸ“¦ IoT: πŸ”΄ WiFi no longer connected, establishing connection…
My code's as follows:
int Iot :: initializeMqttClient() {
stateMqttClientOk = false;
if (!isConnectedToIp()) return 2;
log("Init MQTT client");
#if SUPPORT_IOT_DPS
#else
if (sasToken->Generate(SAS_TOKEN_DURATION_IN_MINUTES) != 0) {
error("Failed generating SAS token");
return 1;
}
else {
success("Successfully generated SAS token from %s", sasToken->moduleName());
}
#endif
mqttConnectionState = IOT_MQTT_CONNECTING;
// == If a client is already there, destroy it before creating a new one
if (mqtt_client) {
log("MQTT client already exists, remove it for a brand new one");
(void)esp_mqtt_client_destroy(mqtt_client);
}
// == Create a new mqtt client
esp_mqtt_client_config_t mqtt_config;
memset(&mqtt_config, 0, sizeof(mqtt_config));
mqtt_config.uri = mqtt_broker_uri;
mqtt_config.port = mqtt_port;
mqtt_config.client_id = mqtt_client_id;
mqtt_config.username = mqtt_username;
az_span t = sasToken->get();
#if LOG_LEVEL >= LOG_LEVEL_DEBUG
log("SAS token: sasToken is %p", sasToken);
log("SAS token: sasToken->get() is %p", t);
#endif
mqtt_config.password = (const char*)az_span_ptr(t);
// == Removed 30s period heartbeat down to 120s (default)
//mqtt_config.keepalive = 30;
mqtt_config.disable_clean_session = 0;
mqtt_config.disable_auto_reconnect = false;
mqtt_config.event_handle = mqtt_event_handler;
mqtt_config.user_context = NULL;
//== Removed the certificate as it makes MQTT crash with the following:
// E (21414) TRANS_SSL: ssl_poll_read select error 113, errno = Software caused connection abort, fd = 54
// E (21416) MQTT_CLIENT: Poll read error: 0, aborting connection
//mqtt_config.cert_pem = (const char*)ca_pem;
mqtt_client = esp_mqtt_client_init(&mqtt_config);
if (mqtt_client == NULL) {
error("Failed creating mqtt client");
return 1;
}
else {
success("Successfully create MQTT client, now let's start it");
}
I tried to comment out the two lines without any noticeable improvement, as follows:
// == Removed this by Sdl on Thursday October 13th 2022 3:15pm
//mqtt_config.disable_clean_session = 0;
//mqtt_config.disable_auto_reconnect = false;
There is probably something wrong with my config code. Any idea?
Also, it would probably be interesting to unmount the MQTT and mount it back again in order to continue doing the collection. But how can this be done?
[UPDATE]
The SAS is checked on a regular basis (and will be updated if expired). But in my case it did not expire (You can see the line the SAS did not expire in the provided logs).
What I should mention is that after a lost of connection (typically between 5 to 15 minutes), MQTT some time manages to reconnect and then succeeds to send a few messages before losing the connection again.

My arduino variable for server name is not seen inside the connect() call

I have this running on an esp8266 but I suspect it's a c/c++ issue, most likely with me not understanding something basic.
I'm trying to connect to a mqtt server set by a value read from a json config file. Debug of the connect() call doesn't see the value I've assigned to the variable. The connect call is failing as the server name to connect to is blank, but only inside the connect() call.
What's the proper way to do this type of call?
Code snippet:
Adafruit_MQTT_Client *mqtt;
const char* _MqttServer = NULL;
setup {
// ...
// read file, parse json, gets the correct value
_MqttServer = jObject["mqttserver"];
// port/username/key are setup as #define earlier
mqtt = new Adafruit_MQTT_Client(&client, _MqttServer, MQTT_SERVERPORT, MQTT_USERNAME, MQTT_KEY);
while ((ret = mqtt->connect()) != 0) { // connect will return 0 for connected
Serial.println(mqtt->connectErrorString(ret));
Serial.println(_MqttServer); // prints correct value
mqtt->disconnect();
delay(5000); // wait 5 seconds
}
// ...
}
The error printed is from
bool Adafruit_MQTT_Client::connectServer() {
// Grab server name from flash and copy to buffer for name resolution.
memset(buffer, 0, sizeof(buffer));
strcpy((char *)buffer, servername);
Serial.print(F("Connecting to: ")); Serial.print((char *)buffer);
The error I get is
Connection failed!
Connecting to:
Connect result: 0
Retrying MQTT connection in 5 seconds...
If I change the _MqttServer to a #define and remove it from assignment to the json it connects normally. I've done that in the meantime to get the device working. The issue I'm seeing is the passing or the assignment of the variable that is not being seen by the called function.

Scala + ZMQ = Operation cannot be accomplished in current state

I am trying to get a Scala program to communicate with a c++ program via zeromq by using the request-reply pattern. The scala program should send a request to the C++ program which replies.
However I see the error
org.zeromq.ZMQException: Operation cannot be accomplished in current state
But all I can find in the docu is that one has to read responses before sending a second request. In my case I am issuing a request, followed by a reading of the response (this is where the exception is thrown).
Code of the server:
#include "zmq.hpp"
#include <string>
#include <iostream>
#include <thread>
int main()
{
zmq::context_t context(1);
zmq::socket_t socket(context, ZMQ_REP);
socket.bind("tcp://*:5555");
while (1) {
zmq::message_t request;
socket.recv(&request);
std::string requ = std::string(static_cast<char*>(request.data()), request.size());
std::cout << requ << std::endl;
// Write response
zmq::message_t req(2);
memcpy((void *)req.data(), "ok", 5);
socket.send(req);
}
}
Code of the client:
import org.zeromq.ZMQ
import org.zeromq.ZMQ.{Context, Socket}
object Adapter {
def main( args: Array[String] ) = {
val context = ZMQ.context(1)
val socket = context.socket(ZMQ.REQ)
println { "Connecting to backend" }
socket.connect("tcp://127.0.0.1:5555")
val request = "1 1 1 1".getBytes()
request(request.length - 1) = 0.toByte
println { "Sending Request" }
if (!socket.send(request, 0))
println{ "could not send"}
println { "Receiving Response" }
val reply = socket.recv(0)
println { "Received reply: " + new String(reply, 0, reply.length - 1) }
}
}
The complete output of sbt:
OpenJDK 64-Bit Server VM warning: You have loaded library /tmp/jna7980154308052950568.tmp which might have disabled stack guard. The VM will try to fix the stack guard now.
It's highly recommended that you fix the library with 'execstack -c <libfile>', or link it with '-z noexecstack'.
Connecting to backend
Sending Request
Receiving Response
[error] (run-main-0) org.zeromq.ZMQException: Operation cannot be accomplished in current state
org.zeromq.ZMQException: Operation cannot be accomplished in current state
at org.zeromq.ZMQ$Socket.raiseZMQException(ZMQ.java:448)
at org.zeromq.ZMQ$Socket.recv(ZMQ.java:368)
at ZeroMQActor$.main(ZeroMQExample.scala:56)
at ZeroMQActor.main(ZeroMQExample.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
[trace] Stack trace suppressed: run last compile:run for the full output.
java.lang.RuntimeException: Nonzero exit code: 1
at scala.sys.package$.error(package.scala:27)
[trace] Stack trace suppressed: run last compile:run for the full output.
[error] (compile:run) Nonzero exit code: 1
[error] Total time: 5 s, completed Jun 16, 2015 4:42:42 PM
Sbt pulls Scala 2.9.1 and akka-zeromq 2.0. I have installed zeromq 3.5 from source but I see the same behavior when I install the ubuntu package libzqm3-dev. One possible work-around is using JeroMQ, a pure java-based implementation of zmq, but I would prefer to depend on one zmq library in my whole stack rather than dealing with interop issues.
Thanks in advance.
I believe
memcpy((void *)req.data(), "ok", 5);
should be
memcpy((void *)req.data(), "ok", 2);
... which could be enough to break message handling.

How to handle AskTime out Exception in Playframework?

The play application which we are using, has to be kept always alive. This application is basically a RabbitMQ listener which has an infinite while loop, which keeps listening to capture the messages from Message Queue.
The following code is placed in controller, and this play application has to be kept alive at all times
public class Application extends Controller {
public static Result wanHLPT() {
ckmsg()
return ok();
}
public static Result ckmsg() {
try{
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.queueDeclare(QUEUE_NAME, false, false, false, null);
while (true) {
QueueingConsumer.Delivery delivery = consumer.nextDelivery();
String message = new String(delivery.getBody());
// business logic
process()
}
}
}
}
But the play application throws akka exception [AskTimeOut Exception: Timed Out],
Please provide any pointers on how to handle this.
Here is the exception:
! #6f977jo6m - Internal server error, for (GET) [/myapp] ->
play.api.Application$$anon$1: Execution exception[[AskTimeoutException: Timed out]]
at play.api.Application$class.handleError(Application.scala:289) ~ [play_2.10.jar:2.1.0]
at play.api.DefaultApplication.handleError(Application.scala:383) ~[play_2.10.jar:2.1.0]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anon$2$$anonfun$handle$1.apply(PlayDefaultUpstreamHandler.scala:132) ~[play_2.10.jar:2.1.0]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anon$2$$anonfun$handle$1.apply(PlayDefaultUpstreamHandler.scala:128) ~[play_2.10.jar:2.1.0]
at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:113) ~[play_2.10.jar:2.1.0]
at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:113) ~[play_2.10.jar:2.1.0]
at play.api.libs.concurrent.PlayPromise$$anonfun$extend$1$$anonfun$apply$1.apply(Promise.scala:104) ~[play_2.10.jar:2.1.0]
at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24) ~[scala-library.jar:na]
at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24) ~[scala-library.jar:na]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) ~[na:1.7.0]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) ~[na:1.7.0]
at java.lang.Thread.run(Thread.java:781) ~[na:1.7.0]
akka.pattern.AskTimeoutException: Timed out
at akka.pattern.PromiseActorRef$$anonfun$1.apply$mcV$sp(AskSupport.scala:310) ~[akka-actor_2.10.jar:na]
at akka.actor.DefaultScheduler$$anon$8.run(Scheduler.scala:193) ~[akka-actor_2.10.jar:na]
at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:137) ~[akka-actor_2.10.jar:na]
at scala.concurrent.forkjoin.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1417) ~[scala-library.jar:na]
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:262) ~[scala-library.jar:na]
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:975) ~[scala-library.jar:na]
at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1478) ~[scala-library.jar:na]
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104) ~[scala-library.jar:na]