quarkus icon indicating copy to clipboard operation
quarkus copied to clipboard

smallrye.mutiny.TimeoutException when trying to connect to redis in Sentinel mode

Open srigano opened this issue 3 years ago • 11 comments

Describe the bug

I'm using quarkus 2.7.5.Final. With redis client, In standalone mode, it works fine:

image

but in sentinel mode it doesn't work:

image

i think this issue could come from the value of quarkus.redis.hosts variable.

I actually put this value : quarkus.redis.hosts=redis://[IP]:8001

At this point, quarkus doesn't know my database Name.

in the help page, i can read this =

image

but i think there is a mistake here: image

if i put my databasename like this:

quarkus.redis.hosts=redis://[IP]:8001/MYDBNAME

i got a FormatNumberException.

this error seems to be normal, because in the vertx Redis Client documentation (https://vertx.io/docs/vertx-redis-client/java/#_connecting_to_redis) we can see this:

image

So the key is :be should not put a database name, but a database number which is expected by the redis client...

Anyway even with a database number it doesn't work for me, I'm getting a timeout exception and I don't know why....

Thank you for you help

I put my code, juste below.

Expected behavior

No response

Actual behavior

No response

How to Reproduce?

here is my code:

  1. in my pom.xml file:
<dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-redis-client</artifactId>
</dependency>
  1. in my resource file:
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;

import fr.ca.cat.echeance.redis.RedisService;

@Path("/redis")
public class RedisResource {
	
    @Inject RedisService redisService;

    @GET
    @Path("/get")
    public String sentinel() {
        //redisService.set("blah", "blih");
        String result = redisService.get("blah");
        return result;
    }
}
  1. in my service file:
@Singleton
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class RedisService {

    @Inject RedisClient redisClient;   

    public String get(String key) {
        return redisClient.get(key).toString();
    }

    public void set(String key, String value) {
        redisClient.set(Arrays.asList(key, value));
    }

}
  1. in my application.properties file, add (replace [IP_ADRESSE] by the good value):

#Redis quarkus.redis.hosts=redis://[IP_ADRESS]:8001 quarkus.redis.client-type=sentinel quarkus.redis.password=mypass

Output of uname -a or ver

linux

Output of java -version

jdk 11

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.7.5.Final

Build tool (ie. output of mvnw --version or gradlew --version)

mvn 3.8.2

Additional information

No response

srigano avatar Apr 01 '22 13:04 srigano

/cc @Ladicek, @cescoffier, @gsmet, @jmartisk, @jponge, @machi1990, @phillip-kruger, @radcortez

quarkus-bot[bot] avatar Apr 01 '22 13:04 quarkus-bot[bot]

Hi, Anyone ?

srigano avatar Apr 05 '22 08:04 srigano

Hello Could you please take a look to my issue?

srigano avatar Apr 12 '22 10:04 srigano

The timeout indicate that it was not able to store the data within a 10s delay (I think that's the defailt(. We would need a proper reproducer indicating how you ran your redis.

cescoffier avatar Apr 12 '22 11:04 cescoffier

I unfortunately don't have the hand to the redis cluster. But I can run some config commands. I'm going to do that.

srigano avatar Apr 12 '22 13:04 srigano

any idea ?

srigano avatar Jun 13 '22 06:06 srigano

I believe this is fixed in https://github.com/quarkusio/quarkus/pull/26268

cescoffier avatar Jun 22 '22 08:06 cescoffier

Hello,

This is not fixed. I am using Quarkus 2.13.2. I tried to use the new Quarkus Redis Client API and also, the Vertx Redis Client API. Both doesn't works. I'm still gettings the same error.

Here is my application.properties:

quarkus.redis.hosts=redis://x.x.x.x:8001/1,redis://y.y.y.y:8001/1,redis://z.z.z.z:8001/1 quarkus.redis.client-type=sentinel quarkus.redis.password=${REDIS_PASSWORD} quarkus.redis.master-name=${REDIS_DB_NAME}

whats does mean the arg "db-number" ?

srigano avatar Oct 18 '22 06:10 srigano

Here is my code:

RedisRessource: `@Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Path("/redis") public class RedisResource { private static final Logger Log = Logger.getLogger(RedisResource.class);

@Inject RedisService redisService;

@POST
@Path("/add")
public MyRedisObject add(MyRedisObject myRedisObject) {
    redisService.add(myRedisObject);
    return myRedisObject;
}

@GET
@Path("/read/{key}")
public String get(String key) {
    MyRedisObject myRedisObject = redisService.get(key);
    key = myRedisObject.getKey();
    return key;
}`

RedisService: `@ApplicationScoped public class RedisService {

private SetCommands<String, MyRedisObject> commands;

 public RedisService(RedisDataSource redisDataSource) {
    commands = redisDataSource.set(MyRedisObject.class);
} 

public void add(MyRedisObject myRedisObject) {
    commands.sadd("key", myRedisObject);
}

public MyRedisObject get(String key) {
    MyRedisObject returnValue = commands.spop(key);
    return returnValue;

}`

MyRedisObject: `public class MyRedisObject { public String key; public String value;

public MyRedisObject(String key, String value) {
    this.key = key;
    this.value = value;
}

public MyRedisObject() {
}

public String getKey() {
    return key;
}

public void setKey(String key) {
    this.key = key;
}

public String getValue() {
    return value;
}

public void setValue(String value) {
    this.value = value;
}    `

-> doesn't work and i don't know what i'm doing wrong regarding to the documation...

the output:

{ "details": "Error id 03d22e3e-4f48-4a72-b406-5c9ebfadfcda-1, io.smallrye.mutiny.TimeoutException: ", "stack": "io.smallrye.mutiny.TimeoutException\r\n\tat io.smallrye.mutiny.operators.uni.UniBlockingAwait.await(UniBlockingAwait.java:64)\r\n\tat io.smallrye.mutiny.groups.UniAwait.atMost(UniAwait.java:65)\r\n\tat io.quarkus.redis.runtime.datasource.BlockingSetCommandsImpl.sadd(BlockingSetCommandsImpl.java:25)\r\n\tat fr.ca.cat.ccc.service.RedisService.add(RedisService.java:25)\r\n\tat fr.ca.cat.ccc.service.RedisService_Subclass.add$$superforward1(Unknown Source)\r\n\tat fr.ca.cat.ccc.service.RedisService_Subclass$$function$$2.apply(Unknown Source)\r\n\tat io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:54)\r\n\tat io.quarkus.arc.runtime.devconsole.InvocationInterceptor.proceed(InvocationInterceptor.java:62)\r\n\tat io.quarkus.arc.runtime.devconsole.InvocationInterceptor.monitor(InvocationInterceptor.java:49)\r\n\tat io.quarkus.arc.runtime.devconsole.InvocationInterceptor_Bean.intercept(Unknown Source)\r\n\tat io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:42)\r\n\tat io.quarkus.arc.impl.AroundInvokeInvocationContext.perform(AroundInvokeInvocationContext.java:41)\r\n\tat io.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:33)\r\n\tat fr.ca.cat.ccc.service.RedisService_Subclass.add(Unknown Source)\r\n\tat fr.ca.cat.ccc.service.RedisService_ClientProxy.add(Unknown Source)\r\n\tat fr.ca.cat.ccc.rest.RedisResource.add(RedisResource.java:25)\r\n\tat fr.ca.cat.ccc.rest.RedisResource_Subclass.add$$superforward1(Unknown Source)\r\n\tat fr.ca.cat.ccc.rest.RedisResource_Subclass$$function$$1.apply(Unknown Source)\r\n\tat io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:54)\r\n\tat io.quarkus.arc.runtime.devconsole.InvocationInterceptor.proceed(InvocationInterceptor.java:62)\r\n\tat io.quarkus.arc.runtime.devconsole.InvocationInterceptor.monitor(InvocationInterceptor.java:49)\r\n\tat io.quarkus.arc.runtime.devconsole.InvocationInterceptor_Bean.intercept(Unknown Source)\r\n\tat io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:42)\r\n\tat io.quarkus.arc.impl.AroundInvokeInvocationContext.perform(AroundInvokeInvocationContext.java:41)\r\n\tat io.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:33)\r\n\tat fr.ca.cat.ccc.rest.RedisResource_Subclass.add(Unknown Source)\r\n\tat fr.ca.cat.ccc.rest.RedisResource$quarkusrestinvoker$add_e98c0d7005adbbdafbf9675f65d5855b28e1fcce.invoke(Unknown Source)\r\n\tat org.jboss.resteasy.reactive.server.handlers.InvocationHandler.handle(InvocationHandler.java:29)\r\n\tat io.quarkus.resteasy.reactive.server.runtime.QuarkusResteasyReactiveRequestContext.invokeHandler(QuarkusResteasyReactiveRequestContext.java:115)\r\n\tat org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:142)\r\n\tat io.quarkus.vertx.core.runtime.VertxCoreRecorder$14.runWith(VertxCoreRecorder.java:564)\r\n\tat org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)\r\n\tat org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)\r\n\tat org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)\r\n\tat org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)\r\n\tat io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)\r\n\tat java.base/java.lang.Thread.run(Thread.java:833)" }

srigano avatar Oct 18 '22 06:10 srigano

How do you run your Redis in sentinel mode? Note that it seems that this mode is likely going to be replaced by the clustered mode.

cescoffier avatar Oct 18 '22 14:10 cescoffier

whats does mean the arg "db-number" ?

@srigano I believe that db-number is an integer value (0..15) indicating the logical database you're connecting to. According to this DigitalOcean page, the default database number you typically connect to is 0.

With only that tidbit of info to go on, can you try changing the db-number you're connecting to from 1 to 0 in application.properties, like so?

quarkus.redis.hosts=redis://x.x.x.x:8001/0,redis://y.y.y.y:8001/0,redis://z.z.z.z:8001/0 

Or maybe it's just worth trying to omit the db-number, as Quarkus' official "Sentinel Mode" documentation does in their code example:

quarkus.redis.hosts=redis://x.x.x.x:8001,redis://y.y.y.y:8001,redis://z.z.z.z:8001 

@cescoffier (and also @srigano): Quarkus' official "Sentinel Mode" documentation indicates that your configuration must define multiple host URLs, in addition to setting the client type:

quarkus.redis.hosts=redis://localhost:5000,redis://localhost:5001,redis://localhost:5002
quarkus.redis.client-type=sentinel

# Optional
quarkus.redis.master-name=my-sentinel # Default is my-master
quarkus.redis.role=master # master is the default

With that in mind, it would make sense that @srigano 's original attempt at connecting in Sentinel mode failed, because it looks like he was only defining a single host URL.

jehrenzweig-leagueapps avatar Mar 08 '23 19:03 jehrenzweig-leagueapps

I have no idea why the timeout should occur here, but I'd like to point out that until https://github.com/vert-x3/vertx-redis-client/pull/429 is merged and gets into Quarkus, sentinel users should always configure both quarkus.redis.master-name and quarkus.redis.role. They should default to the documented values, but that defaulting currently has a bug.

Ladicek avatar Mar 01 '24 16:03 Ladicek