Skip to content
\n
\n \n\n \n \n \n \n
func dial(dst string, opt *ClientOption) (conn net.Conn, err error) {
\n
\n
\n
\nthe dial function to make it accept a context and use Dialer.DialContext to make a connection, and then we also need to update all the intermediate code paths that use the dial function under the hood.

\n

Before that, you can set connection timeout at ClientOption.Dialer.Timeout:

\n
\tclient, err := rueidis.NewClient(rueidis.ClientOption{\n\t\tDialer: net.Dialer{\n\t\t\tTimeout: 30 * time.Millisecond,\n\t\t},\n\t\tBlockingPoolSize: 1024,\n\t})
\n

Also note that you should make sure you never hit the BlockingPoolSize because once the pool is full it also gets stuck if no free connections.

","upvoteCount":1,"url":"https://github.com/redis/rueidis/discussions/798#discussioncomment-12482804"}}}
/ rueidis Public

The time for acquire a new connection is not counted when setting context timeout for a query #798

Answered by rueian
liuzhaohui asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @liuzhaohui,

Yes, currently acquiring a connection doesn't respect the context deadline. To respect it, we need to update:

func dial(dst string, opt *ClientOption) (conn net.Conn, err error) {

the dial function to make it accept a context and use Dialer.DialContext to make a connection, and then we also need to update all the intermediate code paths that use the dial function under the hood.

Before that, you can set connection timeout at ClientOption.Dialer.Timeout:

	client, err := rueidis.NewClient(rueidis.ClientOption{
		Dialer: net.Dialer{
			Timeout: 30 * time.Millisecond,
		},
		BlockingPoolSize: 1024,
	})

Also note that you…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@liuzhaohui
Comment options

@rueian
Comment options

@liuzhaohui
Comment options

Answer selected by liuzhaohui
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants