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

[BUG] Use a custom redis client that will panic if redis close #635

Open
shuqingzai opened this issue Mar 31, 2023 · 7 comments
Open

[BUG] Use a custom redis client that will panic if redis close #635

shuqingzai opened this issue Mar 31, 2023 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@shuqingzai
Copy link

shuqingzai commented Mar 31, 2023

Describe the bug
If you implement the asynq.RedisConnOpt interface and provide a custom redis client, Ctrl + C stops the asynq.Server and asynq.Subscriber panics

To Reproduce
Steps to reproduce the behavior (Code snippets if applicable):

  1. Implement the asynq.RedisConnOpt interface and provide a custom redis client
  2. Instantiate asynq.Server and set up a custom redis client
  3. Start the Server
  4. Stop custom redis client and asynq.RedisConnOpt return nil
  5. Ctrl + C stops the Server, asynq.Subscriber panics

Expected behavior

Can support custom providing redis client instead of panic

Because asynq will start multiple redis clients, and redis will also be used in my project, I hope that only one redis client can be instantiated for unified management and reuse clients

Screenshots
If applicable, add screenshots to help explain your problem.

  1. my redis client

Implement the asynq.RedisConnOpt interface

image

stop custom redis client will return nil

  1. asynq.Subscriber panics
    image

image

Because my redis client returns nil ??

Environment (please complete the following information):

  • OS: [e.g. MacOS, Linux]
MacOS
  • Version of asynq package [e.g. v1.0.0]
v0.24.0

Additional context
Add any other context about the problem here.

@shuqingzai shuqingzai added the bug Something isn't working label Mar 31, 2023
@bfwbbrj
Copy link

bfwbbrj commented Mar 31, 2023

@shuqingzai My guess would be the msg is nil. And this is related to to the pubsub returned by your custom redis's Subscribe. Since I have no idea which lib you are using, you probably need to check your lib's implementation.

@shuqingzai
Copy link
Author

@shuqingzai My guess would be the msg is nil. And this is related to to the pubsub returned by your custom redis's Subscribe. Since I have no idea which lib you are using, you probably need to check your lib's implementation.

@bfwbbrj First of all, thank you for answering my question

  1. What do you mean by library?
  2. I have not changed any configuration and the payload field has not been modified. I just switch my own Redis client back to asynq's built-in implementation and there will be no panic, but using my own implementation will cause panic

@bfwbbrj
Copy link

bfwbbrj commented Apr 1, 2023

What do you mean by library?

The redis client implementation that you are using.

I have not changed any configuration and the payload field has not been modified. I just switch my own Redis client back to asynq's built-in implementation and there will be no panic, but using my own implementation will cause panic

It should be related to the Subscribe method of your redis client implementation. Can you share which redis client implementation you are using?

@shuqingzai
Copy link
Author

What do you mean by library?

The redis client implementation that you are using.

I have not changed any configuration and the payload field has not been modified. I just switch my own Redis client back to asynq's built-in implementation and there will be no panic, but using my own implementation will cause panic

It should be related to the Subscribe method of your redis client implementation. Can you share which redis client implementation you are using?

Observe my screenshot, using go-redis's built-in interface analysis

See: https://github.com/redis/go-redis/blob/v8/universal.go#L208

image

@bfwbbrj
Copy link

bfwbbrj commented Apr 1, 2023

Observe my screenshot, using go-redis's built-in interface analysis

See: https://github.com/redis/go-redis/blob/v8/universal.go#L208

所以你的m.redisClient也是用https://github.com/redis/go-redis/ 这个库的客户端吗?你现在的问题是你如果在MakeRedisClient里返回一个nil,在关服务器的时候会panic?

@shuqingzai
Copy link
Author

Observe my screenshot, using go-redis's built-in interface analysis
See: https://github.com/redis/go-redis/blob/v8/universal.go#L208

所以你的m.redisClient也是用https://github.com/redis/go-redis/ 这个库的客户端吗?你现在的问题是你如果在MakeRedisClient里返回一个nil,在关服务器的时候会panic?
@bfwbbrj

  1. Yes
  2. Hmm, maybe I closed the Redis client first?

@bfwbbrj
Copy link

bfwbbrj commented Apr 3, 2023

  1. Hmm, maybe I closed the Redis client first?

Is it possible for you not to close the Redis client and leave the work to asynq? Currently if you closed the redis client before you shutdown the asynq, msg will be nil since the channel is already closed. I will create a pr to fix this but since rn prs are not being reviewed and merge. I suggest that you let asynq do the client closing if possible.

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

No branches or pull requests

3 participants