hiredis icon indicating copy to clipboard operation
hiredis copied to clipboard

Is there a way to tell hiredis to disconnect in the async onConnect callback?

Open echoma opened this issue 4 years ago • 2 comments

https://github.com/redis/hiredis/blob/master/async.c#L620 If I call redisAsyncDisconnect() in the onConnect callback, the redisContext pointer "c" will point to a freed memory, this might make a crash.

may be, a REDIS_IN_CALLBACK like flag which protecting the context object will help?

echoma avatar Jun 21 '20 03:06 echoma

The onConnect callback gives you a const redisAsyncContext *ac so you really shouldn't be mutating it there.

What's the use case for this?

michael-grunder avatar Jul 10 '20 16:07 michael-grunder

I am a library writer, the library's user may do some checking logic in business layer in onConnect callback. In some situation, the user would like to close the connection when checking failed. I cant control the user's code, so I came here to see whether there is any solution. @michael-grunder

echoma avatar Jul 11 '20 06:07 echoma

Closing as this is now possible as #931 was merged and then modified slightly in #1087

michael-grunder avatar Sep 01 '22 04:09 michael-grunder