Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
srigano opened this issue Apr 1, 2022 · 12 comments
Labels
area/redis kind/bug Something isn't working

Comments

@srigano
Copy link

srigano commented Apr 1, 2022

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

@quarkus-bot
Copy link

quarkus-bot bot commented Apr 1, 2022

@srigano
Copy link
Author

srigano commented Apr 5, 2022

Hi,
Anyone ?

@srigano
Copy link
Author

srigano commented Apr 12, 2022

Hello
Could you please take a look to my issue?

@cescoffier
Copy link
Member

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.

@srigano
Copy link
Author

srigano commented Apr 12, 2022

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
Copy link
Author

srigano commented Jun 13, 2022

any idea ?

@cescoffier
Copy link
Member

I believe this is fixed in #26268

@srigano
Copy link
Author

srigano commented Oct 18, 2022

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
Copy link
Author

srigano commented Oct 18, 2022

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)" }

@cescoffier
Copy link
Member

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.

@jehrenzweig-leagueapps
Copy link
Contributor

jehrenzweig-leagueapps commented Mar 8, 2023

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.

@Ladicek
Copy link
Contributor

Ladicek commented Mar 1, 2024

I have no idea why the timeout should occur here, but I'd like to point out that until vert-x3/vertx-redis-client#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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/redis kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants