summaryrefslogtreecommitdiff
path: root/async.c
AgeCommit message (Collapse)Author
2022-11-09Make freeing a NULL redisAsyncContext a no op.michael-grunder
This makes our behavior consistent with redisFree and freeReplyObject.
2022-08-29Copy error to redisAsyncContext when finding subscribe cbBjörn Svensson
2022-08-26Maintain backward compatibiliy withour onConnect callback.michael-grunder
In f69fac7690fb22a7fc19dba61ef70e5f79ccb2e9, our async onConnect callback was improved to take a non-const redisAsyncContext allowing it to be reentrant. Unfortunately, this is a breaking change we can't make until hiredis v2.0.0. This commit creates a separate callback member and corresponding function that allows us to use the new functionality, while maintaining our existing API for legacy code. Fixes #1086
2022-07-08Support calling redisAsyncDisconnect from the onConnected callback, by ↵Kristján Valur Jónsson
deferring context deletion
2022-02-03Handle any pipelined unsubscribe in asyncBjörn Svensson
Redis responds to an unsubscribe with one or many replies, depending on the current subscribe state. When channels/patterns names are provided in a command each given name will trigger a reply even if duplicated or not subscribed to. To know when we can return from the subscribed state we need to do bookkeeping on pending additional unsubscribe replies, and make sure we receive them all before switching state.
2022-02-02Ignore pubsub replies without a channel/patternBjörn Svensson
2022-01-27Avoid incorrect call to the previous reply's callback (#1040)Bjorn Svensson
* No reuse of the previous reply callback When multiple replies are parsed from a socket in one read a previously found callback might get reused when the current reply has no known callback. This can be triggered by the added testcase which unsubscribe to subscribed (A,B) and a non-subscribed channel (X). Without this correction a callback for wrong channel is called. - In 'unsubscribe B X A', B's callback is called when handling X. - Now this is not done, i.e. there is no callback called for X. * Re-push monitor callback for each reply MONITORING used the same callback for all replies while parsing multiple responses. This handling was changed to avoid calling the wrong callback in some scenarios. Now also change monitorings repush to work with this change. Includes an added async monitoring testcase.
2022-01-18Allow sending commands after sending an unsubscribe (#1036)Bjorn Svensson
* Add test of async commands after unsubscribe Verify that commands are handled after unsubscribing from a channel. A command is sent before the `unsubscribe` response is received, which currently triggers an assert in async.c:567: `redisProcessCallbacks: Assertion `(c->flags & REDIS_SUBSCRIBED || c->flags & REDIS_MONITORING)' failed.` * Handle async commands after an unsubscribe When unsubscribing from the last channel we move from the `subscribe` state to a normal state. These states uses different holders for the command callback information. By moving the callback info during the state change the callback order can be maintained.
2022-01-11Correction for command timeout during pubsub (#1038)Bjorn Svensson
* Add test of command timeout during pubsub A timeout of a non-subscribe command will be ignored during pubsub. It will be handled as an idle timeout and a response is awaited for. * Correction for command timeout during pubsub Disconnect when a sent non-subscribe command triggers a timeout.
2021-12-22Fix integer overflow when format command larger than 4GB (#1030)sundb
2021-12-22Handle array response in parallell with pubsub using RESP3 (#1014)Bjorn Svensson
RESP3 allows sending commands in parallell with pubsub handling and these commands might get responded with a REDIS_REPLY_ARRAY. This conflicts with the pubsub response handling for RESP2 and results in a faulty state when using RESP3. Add functionality to keep track of PUSH/RESP3 support on the connection and only expect the message type REDIS_REPLY_PUSH as subscribe messages when once seen.
2021-12-16Support PING while subscribing (RESP2) (#1027)Bjorn Svensson
* Handle PING during pubsub in RESP2 * Rename invalid callback list Some commands are valid to send during a subscribe in RESP2, and most in RESP3. Renaming the callback list from `invalid` to `replies` to detail this fact. * Fix review comment
2021-12-01Add asynchronous test for pubsub using RESP3 (#1012)Bjorn Svensson
* Include `unsubscribe` as a subscribe reply in RESP3 By providing the (p)unsubscribe message via the subscribe callback, instead of via the push callback, we get the same behavior in RESP3 as in RESP2. * Add asynchronous test for pubsub using RESP3 The testcase will subscribe to a channel, and via a second client a message is published to the channel. After receiving the message the testcase will unsubscribe and disconnect. This RESP3 testcase reuses the subscribe callback from the RESP2 testcase to make sure we have a common behavior.
2021-07-11Added REDIS_NO_AUTO_FREE_REPLIES flag (#962)Meir Shpilraien (Spielrein)
When set hiredis will not automatically free replies in an async context, and the replies must be freed instead by the user. Co-authored-by: Michael Grunder <michael.grunder@gmail.com>
2021-06-17Ensure we curry any connect error to an async context.michael-grunder
2021-04-08Ignore timeout callback from a successful connectKristján Valur Jónsson
2021-01-26Merge pull request #917 from Nordix/stack-alloc-dict-iterMichael Grunder
Stack allocate dict iterators
2021-01-26Handle OOM during async command callback registrationBjorn Svensson
Unless the callback is pushed to the list it will trigger an assert in redisProcessCallbacks() when the response arrives. This change let the user get an early error instead, available in the async context directly.
2021-01-25Stack allocate dict iteratorsBjorn Svensson
Replacing the get & release functions with an initiation function. Simplifies the code and will make sure we run subscription callbacks in OOM scenarios.
2020-09-23Copy error to redisAsyncContext on timeoutshiyuge
2020-07-31Define a no op assert if we detect NDEBUG (#861)Michael Grunder
Addresses #642
2020-07-26add a command_timeout to redisContextOptions (#839)valentinogeron
Add an additional timeout so the user has a convenient way of controlling distinct connect and command timeouts
2020-07-19Resp3 oob push support (#841)Michael Grunder
Proper support for RESP3 PUSH messages. By default, PUSH messages are now intercepted and the reply memory freed. This means existing code should work unchanged when connecting to Redis >= 6.0.0 even if `CLIENT TRACKING` were then enabled. Additionally, we define two callbacks users can configure if they wish to handle these messages in a custom way: void redisPushFn(void *privdata, void *reply); void redisAsyncPushFn(redisAsyncContext *ac, void *reply); See #825
2020-06-22fix #785: defer TCP_NODELAY in async tcp connections (#836)OmriSteiner
Co-authored-by: Omri Steiner <omri@insoundz.com>
2020-05-22Allow users to replace allocator and handle OOM everywhere. (#800)Michael Grunder
* Adds an indirection to every allocation/deallocation to allow users to plug in ones of their choosing (use custom functions, jemalloc, etc). * Gracefully handle OOM everywhere in hiredis. This should make it possible for users of the library to have more flexibility in how they handle such situations. * Changes `redisReaderTask->elements` from an `int` to a `long long` to prevent a possible overflow when transferring the task elements into a `redisReply`. * Adds a configurable `max elements` member to `redisReader` that defaults to 2^32 - 1. This can be set to "unlimited" by setting the value to zero.
2020-05-21Add logic to handle RESP3 push messages (#819)Michael Grunder
Fixes #815
2020-04-09Provides an optional cleanup callback for async data.Nick Rivera
2020-01-28Safe allocation wrappers (#754)Michael Grunder
Create allocation wrappers with a configurable OOM handler (defaults to abort()). See #752, #747
2019-08-29wip: SSL code reorganization, see #705.Yossi Gottlieb
2019-08-09MinGW fix: Use _MSC_VER instead of _WIN32 where appropriateMarcus Geelnard
Use _MSC_VER (instead of _WIN32) for things that are specific for Visual Studio. Also remove #include <winsock2.h> from hiredis.h, as it leaks too many symbols and defines into the global namespace, which is undesirable for a public interface header. Anyone who uses the the affected parts of the hiredis API needs to include the appropriate headers anyway in order to declare struct timeval variables.
2019-07-22Removed whitespace before newlineOdin Hultgren Van Der Horst
- Removed whitespace before newline - Removed win style newline
2019-04-13Fix Compile Error On Windows (Visual Studio)jinjiazhang
2019-03-11Retain the same semantics for connection error on connection timeoutMark Nunberg
This ensures that a disconnect occurs. This commit also ensures that disconnects will clean the socket even if the user is in no-auto-free mode
2019-02-21Allow option for async connections to not automatically freeMark Nunberg
2019-02-20fix potential uninitialized readMark Nunberg
If callback was set before scheduleTimer was set (i..e before one of the attach()) calls.
2019-02-20Allow connectWithOptions for async as wellMark Nunberg
2019-02-20read/write timeoutsMark Nunberg
2019-02-20Don't add dead code for HIREDIS_NOSSLMark Nunberg
We changed this to `HIREDIS_SSL`
2019-02-20SSL for async I/OMark Nunberg
2018-09-25Handle connection errors better in blocking mode as wellMark Nunberg
2018-09-25Call connect(2) again for non-blocking connectMark Nunberg
This retrieves the actual error which occurred, as getsockopt is not always reliable in this regard.
2018-05-09Merge remote-tracking branch 'hyjin/master'michael-grunder
2017-07-15Merge #524 #525not-a-robot[bot]
524: Don't pass a negative value to __redisAsyncCommand if redisFormatSdsCommandArgv fails r=badboy 525: Fix compilation on FreeBSD 10.3 with default compiler r=badboy Given FreeBSD 10.3 with default compiler: > $ cc -v > FreeBSD clang version 3.4.1 (tags/RELEASE_34/dot1-final 208032) 20140512 > Target: x86_64-unknown-freebsd10.3 Defining _XOPEN_SOURCE to 600 on the fixed line leads to the following errors: > cc -std=c99 -pedantic -c -O3 -fPIC -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb net.c > net.c:435:29: error: use of undeclared identifier 'AF_LOCAL' > if (redisCreateSocket(c,AF_LOCAL) < 0) > ^ > net.c:460:21: error: use of undeclared identifier 'AF_LOCAL' > sa.sun_family = AF_LOCAL; > ^ > 2 errors generated. > AF_LOCAL is defined in sys/socket.h within ifdef __BSD_VISIBLE. __BSD_VISIBLE could be defined in sys/cdefs.h, but it is never done if _XOPEN_SOURCE is defined. So on FreeBSD _XOPEN_SOURCE shouldn't be defined.
2017-06-15Assert statement calls a function which has side effectsamallia
2017-05-15Don't pass a negative value to __redisAsyncCommand if ↵Frederik Deweerdt
redisFormatSdsCommandArgv fails
2017-01-30Use cached local variable instead using accessorHyungjin Kim
2017-01-30Consider sub by pattern when clear subscribed flagHyungjin Kim
2016-09-30Counting pending subscribe. Fix #396Hyungjin Kim
2015-10-28fixing typoscharsyam
2015-07-27Prevent crash on pending replies in async codeJan-Erik Rediger
Fixes #335.