1. 12 Jan, 2021 15 commits
    • Oran Agra's avatar
      fix crash in redis-cli after making cluster backup (#8267) · 02e93062
      Oran Agra authored
      getRDB is "designed" to work in two modes: one for redis-cli --rdb and
      one for redis-cli --cluster backup.
      in the later case it uses the hiredis connection from the cluster nodes
      and it used to free it without nullifying the context, so a later
      attempt to free the context would crash.
      
      I suppose the reason it seems to want to free the hiredis context ASAP
      is that it wants to disconnect the replica link, so that replication
      buffers will not be accumulated.
      
      (cherry picked from commit 41b2ed2b)
      02e93062
    • Oran Agra's avatar
      Fix wrong order of key/value in Lua map response (#8266) · ec56906b
      Oran Agra authored
      When a Lua script returns a map to redis (a feature which was added in
      redis 6 together with RESP3), it would have returned the value first and
      the key second.
      
      If the client was using RESP2, it was getting them out of order, and if
      the client was in RESP3, it was getting a map of value => key.
      This was happening regardless of the Lua script using redis.setresp(3)
      or not.
      
      This also affects a case where the script was returning a map which it got
      from from redis by doing something like: redis.setresp(3); return redis.call()
      
      This fix is a breaking change for redis 6.0 users who happened to rely
      on the wrong order (either ones that used redis.setresp(3), or ones that
      returned a map explicitly).
      
      This commit also includes other two changes in the tests:
      1. The test suite now handles RESP3 maps as dicts rather than nested
         lists
      2. Remove some redundant (duplicate) tests from tracking.tcl
      
      (cherry picked from commit 2017407b)
      ec56906b
    • Oran Agra's avatar
      Crash log would crash half way on commands with no arguments (#8260) · 23d29923
      Oran Agra authored
      The crash log attempts to print the current client info, and when it
      does that it attempts to check if the first argument happens to be a key
      but it did so for commands with no arguments too, which caused the crash
      log to crash half way and not reach its end.
      
      (cherry picked from commit 152b5d46)
      23d29923
    • Yossi Gottlieb's avatar
      Fix crashes with io-threads-do-reads enabled. (#8230) · f84c181e
      Yossi Gottlieb authored
      Normally IO threads should simply read data from the socket into the
      buffer and attempt to parse it.
      
      If a protocol error is detected, a reply is generated which may result
      with installing a write handler which is not thread safe. This fix
      delays that until the client is processed back in the main thread.
      
      Fixes #8220
      
      (cherry picked from commit e7047ec2)
      f84c181e
    • George Prekas's avatar
      Add check for the MADV_FREE/fork arm64 Linux kernel bug (#8224) · 8ff02263
      George Prekas authored
      
      
      Older arm64 Linux kernels have a bug that could lead to data corruption during
      background save under the following scenario:
      
      1) jemalloc uses MADV_FREE on a page,
      2) jemalloc reuses and writes the page,
      3) Redis forks the background save process, and
      4) Linux performs page reclamation.
      
      Under these conditions, Linux will reclaim the page wrongfully and the
      background save process will read zeros when it tries to read the page.
      
      The bug has been fixed in Linux with commit:
      ff1712f953e27f0b0718762ec17d0adb15c9fd0b ("arm64: pgtable: Ensure dirty bit is
      preserved across pte_wrprotect()")
      
      This Commit adds an ignore-warnings config, when not found, redis will
      print a warning and exit on startup (default behavior).
      Co-authored-by: default avatarOran Agra <oran@redislabs.com>
      (cherry picked from commit b02780c4)
      
      in 6.0 this warning is ignored by default in order to avoid adding
      regression, specifically for deployments that don't need persistence or
      replication
      8ff02263
    • Qu Chen's avatar
      Not over-allocate client query buffer when reading large objects. (#5954) · d756b11f
      Qu Chen authored
      In response to large client query buffer optimization introduced in 1898e6ce. The calculation of the amount of
      remaining bytes we need to write to the query buffer was calculated wrong, as a result we are unnecessarily
      growing the client query buffer by sdslen(c->querybuf) always. This fix corrects that behavior.
      
      Please note the previous behavior prior to the before-mentioned change was correctly calculating the remaining
      additional bytes, and this change makes that calculate to be consistent.
      
      Useful context, the argument of size `ll` starts at qb_pos (which is now the beginning of the sds), but much of it
      may have already been read from the socket, so we only need to grow the sds for the remainder of it.
      
      (cherry picked from commit 11b3325e)
      d756b11f
    • Oran Agra's avatar
      Handle output buffer limits for Module blocked clients (#8141) · ec74ae7e
      Oran Agra authored
      Module blocked clients cache the response in a temporary client,
      the reply list in this client would be affected by the recent fix
      in #7202, but when the reply is later copied into the real client,
      it would have bypassed all the checks for output buffer limit, which
      would have resulted in both: responding with a partial response to
      the client, and also not disconnecting it at all.
      
      (cherry picked from commit 48efc25f)
      ec74ae7e
    • Yossi Gottlieb's avatar
      Fix setproctitle related crashes. (#8150) · 785851a7
      Yossi Gottlieb authored
      Makes spt_init more careful with assumptions about what memory regions
      may be overwritten. It will now only consider a contiguous block of argv
      and envp elements and mind any gaps.
      
      (cherry picked from commit ec02c761)
      785851a7
    • Yossi Gottlieb's avatar
      Fix use-after-free issue in spt_copyenv. (#8088) · 2a2d5a7a
      Yossi Gottlieb authored
      Seems to have gone unnoticed for a long time, because at least with
      glibc it will only be triggered if setenv() was called before spt_init,
      which Redis doesn't.
      
      Fixes #8064.
      
      (cherry picked from commit 7e5a6313)
      2a2d5a7a
    • Wang Yuan's avatar
      Backup keys to slots map and restore when fail to sync if diskless-load type... · a60ed4a5
      Wang Yuan authored
      
      Backup keys to slots map and restore when fail to sync if diskless-load type is swapdb in cluster mode (#8108)
      
      When replica diskless-load type is swapdb in cluster mode, we didn't backup
      keys to slots map, so we will lose keys to slots map if fail to sync.
      Now we backup keys to slots map at first, and restore it properly when fail.
      
      This commit includes a refactory/cleanup of the backups mechanism (moving it to db.c and re-structuring it a bit).
      Co-authored-by: default avatarOran Agra <oran@redislabs.com>
      (cherry picked from commit b55a827e)
      a60ed4a5
    • Wang Yuan's avatar
      Reset average ttl when empty databases (#8106) · 5ed66621
      Wang Yuan authored
      On FLUSHDB or full sync, reset old average TTL stat.
      This Stat is incrementally collected by the master over time when it searches for expired keys. 
      
      (cherry picked from commit c85bf235)
      5ed66621
    • Oran Agra's avatar
      Fix bug with module GIL being released prematurely (#8061) · f885e364
      Oran Agra authored
      This is hopefully usually harmles.
      The server.ready_keys will usually be empty so the code after releasing
      the GIL will soon be done.
      The only case where it'll actually process things is when a module
      releases a client (or module) blocked on a key, by triggering this NOT
      from within a command (e.g. a timer event).
      
      This bug was introduced in redis 6.0.9, see #7903
      
      (cherry picked from commit e6fa4738)
      f885e364
    • Oran Agra's avatar
      Fix oom-score-adj-values range, abs options, and bug when used in config file (#8046) · 3ac666b3
      Oran Agra authored
      Fix: When oom-score-adj-values is provided in the config file after
      oom-score-adj yes, it'll take an immediate action, before
      readOOMScoreAdj was acquired, resulting in an error (out of range score
      due to uninitialized value. delay the reaction the real call is made by
      main().
      
      Since the values are clamped to -1000..1000, and they're
      applied as an offset from the value at startup (which may be -1000), we
      need to allow the offsets to reach to +2000 so that a value of +1000 is
      achievable in case the value at startup was -1000.
      
      Adding an option for absolute values rather than relative ones.
      
      (cherry picked from commit 61954951)
      3ac666b3
    • guybe7's avatar
      EXISTS should not alter LRU, OBJECT should not reveal expired keys on replica (#8016) · 4b37eb13
      guybe7 authored
      The bug was introduced by #5021 which only attempted avoid EXIST on an
      already expired key from returning 1 on a replica.
      
      Before that commit, dbExists was used instead of
      lookupKeyRead (which had an undesired effect to "touch" the LRU/LFU)
      
      Other than that, this commit fixes OBJECT to also come empty handed on
      expired keys in replica.
      
      And DEBUG DIGEST-VALUE to behave like DEBUG OBJECT (get the data from
      the key regardless of it's expired state)
      
      (cherry picked from commit f8ae9917)
      4b37eb13
    • Wang Yuan's avatar
      Disable rehash when redis has child process (#8007) · 3a13c654
      Wang Yuan authored
      In redisFork(), we don't set child pid, so updateDictResizePolicy()
      doesn't take effect, that isn't friendly for copy-on-write.
      
      The bug was introduced this in redis 6.0: 56258c6b
      
      (cherry picked from commit 89c78a98)
      3a13c654
  2. 27 Oct, 2020 25 commits
    • Oran Agra's avatar
      Redis 6.0.9. · 25214bd7
      Oran Agra authored
      25214bd7
    • Yossi Gottlieb's avatar
      Fix wrong zmalloc_size() assumption. (#7963) · 3cc673bd
      Yossi Gottlieb authored
      When using a system with no malloc_usable_size(), zmalloc_size() assumed
      that the heap allocator always returns blocks that are long-padded.
      
      This may not always be the case, and will result with zmalloc_size()
      returning a size that is bigger than allocated. At least in one case
      this leads to out of bound write, process crash and a potential security
      vulnerability.
      
      Effectively this does not affect the vast majority of users, who use
      jemalloc or glibc.
      
      This problem along with a (different) fix was reported by Drew DeVault.
      
      (cherry picked from commit 9824fe3e)
      3cc673bd
    • Oran Agra's avatar
      Attempt to fix sporadic test failures due to wait_for_log_messages (#7955) · de0919cd
      Oran Agra authored
      The tests sometimes fail to find a log message.
      Recently i added a print that shows the log files that are searched
      and it shows that the message was in deed there.
      The only reason i can't think of for this seach to fail, is we we
      happened to read an incomplete line, which didn't match our pattern and
      then on the next iteration we would continue reading from the line after
      it.
      
      The fix is to always re-evaluation the previous line.
      
      (cherry picked from commit 4e2e5be2)
      de0919cd
    • David CARLIER's avatar
      cpu affinity: DragonFlyBSD support (#7956) · 5aa0fef2
      David CARLIER authored
      
      (cherry picked from commit 27f4c212)
      5aa0fef2
    • Zach Fewtrell's avatar
      fix invalid 'failover' identifier in cluster slave selection test (#7942) · 3988e32f
      Zach Fewtrell authored
      
      (cherry picked from commit ebfa7699)
      3988e32f
    • WuYunlong's avatar
      Update rdb_last_bgsave_time_sec in INFO on diskless replication (#7917) · 6f16e52a
      WuYunlong authored
      `info Persistence` will include correct (updated) rdb_last_bgsave_time_sec
      For diskless bgsave (sockets) too (like a few other persistence info fields).
      
      Refactor code to reduce duplicate code.
      
      (cherry picked from commit e05a7df7)
      6f16e52a
    • Wen Hui's avatar
      do not add save parameter during config rewrite in sentinel mode (#7945) · c6c2de95
      Wen Hui authored
      Previous code would have added default redis save parameters
      to the config file on rewrite, which would have been silently ignored
      when the config file is loaded.
      
      The new code avoids adding this, and also actively removes these lines
      If added by a previous config rewrite. 
      
      (cherry picked from commit 0f370f9b)
      c6c2de95
    • Qu Chen's avatar
      WATCH no longer ignores keys which have expired for MULTI/EXEC. (#7920) · cebc1f26
      Qu Chen authored
      This wrong behavior was backed by a test, and also documentation, and dates back to 2010.
      But it makes no sense to anyone involved so it was decided to change that.
      
      Note that 20eeddfb (invalidate watch on expire on access) was released in 6.0 RC2
      and 2d1968f8 released in in 6.0.0 GA (invalidate watch when key is evicted).
      both of which do similar changes.
      
      (cherry picked from commit 556acefe)
      cebc1f26
    • Oran Agra's avatar
      improve verbose logging on failed test. print log file lines (#7938) · 56d8ad93
      Oran Agra authored
      
      (cherry picked from commit c96ece9f)
      56d8ad93
    • Yossi Gottlieb's avatar
      Add a --no-latency tests flag. (#7939) · 0103dc09
      Yossi Gottlieb authored
      Useful for running tests on systems which may be way slower than usual.
      
      (cherry picked from commit 843a13e8)
      0103dc09
    • filipe oliveira's avatar
      Fixed bug concerning redis-benchmark non clustered benchmark forcing always... · 71c1427a
      filipe oliveira authored
      
      Fixed bug concerning redis-benchmark non clustered benchmark forcing always the same hash tag {tag} (#7931)
      
      Adding the ":{tag}" only if --cluster is used, so that when used against
      a proxy it generates traffic to all shards.
      Co-authored-by: default avatarOran Agra <oran@redislabs.com>
      (cherry picked from commit 6cf23d66)
      71c1427a
    • Oran Agra's avatar
      fix 32bit build warnings (#7926) · 30bb0dd5
      Oran Agra authored
      
      (cherry picked from commit a425e1d2)
      30bb0dd5
    • Wen Hui's avatar
      fix double fclose in aofrewrite (#7919) · 99f39d32
      Wen Hui authored
      minor fix for a bug which happen on error handling code
      and doesn't look like it could have caused any real harm
      (fd number wouldn't have been reused yet)
      
      (cherry picked from commit 04a0af90)
      99f39d32
    • Oran Agra's avatar
      INFO report peak memory before eviction (#7894) · 851ec530
      Oran Agra authored
      In some cases one command added a very big bulk of memory, and this
      would be "resolved" by the eviction before the next command.
      
      Seeing an unexplained mass eviction we would wish to
      know the highest momentary usage too.
      
      Tracking it in call() and beforeSleep() adds some hooks in AOF and RDB
      loading.
      
      The fix in clientsCronTrackExpansiveClients is related to #7874
      
      (cherry picked from commit 457b7073)
      851ec530
    • Yossi Gottlieb's avatar
      Fix tests failure on busybox systems. (#7916) · 79e6ab31
      Yossi Gottlieb authored
      
      (cherry picked from commit ef92f507)
      79e6ab31
    • Oran Agra's avatar
      Allow requirepass config to clear the password (#7899) · b20af834
      Oran Agra authored
      This is a compatibility issue with redis 5.0 that was introduced by ACL.
      Before this commit, setting requirepass to an empty string will result
      in a server that needs an empty AUTH, unlike redis 5.0 which would
      accept connections without an AUTH.
      
      (cherry picked from commit 19418b6b)
      b20af834
    • Wang Yuan's avatar
      Remove temporary aof and rdb files in a background thread (#7905) · 14532772
      Wang Yuan authored
      If we fail or stop to rewrite aof, we need to remove temporary aof.
      We also remove temporary rdb when replicas abort to receive rdb.
      But currently we delete them in main thread, to avoid blocking,
      we should use bg_unlink to remove them in a background thread.
      
      Btw, we have already used this way to removed child process temporary rdb.
      
      (cherry picked from commit aaacb8c9)
      14532772
    • guybe7's avatar
      Minor improvements to module blocked on keys (#7903) · e4e24460
      guybe7 authored
      - Clarify some documentation comments
      - Make sure blocked-on-keys client privdata is accessible
        from withing the timeout callback
      - Handle blocked clients in beforeSleep - In case a key
        becomes "ready" outside of processCommand
      
      See #7879 #7880
      
      (cherry picked from commit addf47dc)
      e4e24460
    • Andreas Lind's avatar
      Support redis-cli -u rediss://... (#7900) · db9cffe7
      Andreas Lind authored
      
      (cherry picked from commit 8b497881)
      db9cffe7
    • Yossi Gottlieb's avatar
      Modules: fix RM_GetCommandKeys API. (#7901) · 9c475272
      Yossi Gottlieb authored
      This cleans up and simplifies the API by passing the command name as the
      first argument. Previously the command name was specified explicitly,
      but was still included in the argv.
      
      (cherry picked from commit 056a43e1)
      9c475272
    • Meir Shpilraien (Spielrein)'s avatar
      Add Module API for version and compatibility checks (#7865) · 6f2c894d
      Meir Shpilraien (Spielrein) authored
      
      
      * Introduce a new API's: RM_GetContextFlagsAll, and
      RM_GetKeyspaceNotificationFlagsAll that will return the
      full flags mask of each feature. The module writer can
      check base on this value if the Flags he needs are
      supported or not.
      
      * For each flag, introduce a new value on redismodule.h,
      this value represents the LAST value and should be there
      as a reminder to update it when a new value is added,
      also it will be used in the code to calculate the full
      flags mask (assuming flags are incrementally increasing).
      In addition, stated that the module writer should not use
      the LAST flag directly and he should use the GetFlagAll API's.
      
      * Introduce a new API: RM_IsSubEventSupported, that returns for a given
      event and subevent, whether or not the subevent supported.
      
      * Introduce a new macro RMAPI_FUNC_SUPPORTED(func) that returns whether
      or not a function API is supported by comparing it to NULL.
      
      * Introduce a new API: int RM_GetServerVersion();, that will return the
      current Redis version in the format 0x00MMmmpp; e.g. 0x00060008;
      
      * Changed unstable version from 999.999.999 to 255.255.255
      Co-authored-by: default avatarOran Agra <oran@redislabs.com>
      Co-authored-by: default avatarYossi Gottlieb <yossigo@gmail.com>
      (cherry picked from commit adc3183c)
      6f2c894d
    • Yossi Gottlieb's avatar
      Module API: Add RM_GetClientCertificate(). (#7866) · 4147a220
      Yossi Gottlieb authored
      This API function makes it possible to retrieve the X.509 certificate
      used by clients to authenticate TLS connections.
      
      (cherry picked from commit 0aec98dc)
      4147a220
    • Yossi Gottlieb's avatar
      Modules: Add RM_GetDetachedThreadSafeContext(). (#7886) · 28d1fe67
      Yossi Gottlieb authored
      The main motivation here is to provide a way for modules to create a
      single, global context that can be used for logging.
      
      Currently, it is possible to obtain a thread-safe context that is not
      attached to any blocked client by using `RM_GetThreadSafeContext`.
      However, the attached context is not linked to the module identity so
      log messages produced are not tagged with the module name.
      
      Ideally we'd fix this in `RM_GetThreadSafeContext` itself but as it
      doesn't accept the current context as an argument there's no way to do
      that in a backwards compatible manner.
      
      (cherry picked from commit 907da058)
      28d1fe67
    • Yossi Gottlieb's avatar
      Modules: add RM_GetCommandKeys(). · 116a2042
      Yossi Gottlieb authored
      This is essentially the same as calling COMMAND GETKEYS but provides a
      more efficient interface that can be used in every context (i.e. not a
      Redis command).
      
      (cherry picked from commit 7d117d75)
      116a2042
    • Yossi Gottlieb's avatar
      Introduce getKeysResult for getKeysFromCommand. · 945983ac
      Yossi Gottlieb authored
      Avoid using a static buffer for short key index responses, and make it
      caller's responsibility to stack-allocate a result type. Responses that
      don't fit are still allocated on the heap.
      
      (cherry picked from commit 9b7f8ba8)
      945983ac