Commit Graph

11433 Commits

Author SHA1 Message Date
Binbin
95b88f672a
Set RM_StringCompare input args as const (#11010)
Following #10996, it forgot to modify RM_StringCompare in module.c

Modified RM_StringCompare, compareStringObjectsWithFlags,
compareStringObjects and collateStringObjects.
2022-07-19 08:59:39 +03:00
Binbin
5ce64ab010
Fix timing issue in cluster test (#11008)
A timing issue like this was reported in freebsd daily CI:
```
*** [err]: Sanity test push cmd after resharding in tests/unit/cluster/cli.tcl
Expected 'CLUSTERDOWN The cluster is down' to match '*MOVED*'
```

We additionally wait for each node to reach a consensus on the cluster
state in wait_for_condition to avoid the cluster down error.

The fix just like #10495, quoting madolson's comment:
Cluster check just verifies the the config state is self-consistent,
waiting for cluster_state to be okay is an independent check that all
the nodes actually believe each other are healthy.

At the same time i noticed that unit/moduleapi/cluster.tcl has an exact
same test, may have the same problem, also modified it.
2022-07-18 20:35:13 -07:00
Oran Agra
2825b6057b
Fix heap overflow corruption in XAUTOCLAIM (CVE-2022-31144) (#11002)
The temporary array for deleted entries reply of XAUTOCLAIM was
insufficient, but also in fact the COUNT argument should be used to
control the size of the reply, so instead of terminating the loop by
only counting the claimed entries, we'll count deleted entries as well.

Fix #10968
Addresses CVE-2022-31144
2022-07-18 11:36:19 +03:00
ranshid
eacca729a5
Avoid using unsafe C functions (#10932)
replace use of:
sprintf --> snprintf
strcpy/strncpy  --> redis_strlcpy
strcat/strncat  --> redis_strlcat

**why are we making this change?**
Much of the code uses some unsafe variants or deprecated buffer handling
functions.
While most cases are probably not presenting any issue on the known path
programming errors and unterminated strings might lead to potential
buffer overflows which are not covered by tests.

**As part of this PR we change**
1. added implementation for redis_strlcpy and redis_strlcat based on the strl implementation: https://linux.die.net/man/3/strl
2. change all occurrences of use of sprintf with use of snprintf
3. change occurrences of use of  strcpy/strncpy with redis_strlcpy
4. change occurrences of use of strcat/strncat with redis_strlcat
5. change the behavior of ll2string/ull2string/ld2string so that it will always place null
  termination ('\0') on the output buffer in the first index. this was done in order to make
  the use of these functions more safe in cases were the user will not check the output
  returned by them (for example in rdbRemoveTempFile)
6. we added a compiler directive to issue a deprecation error in case a use of
  sprintf/strcpy/strcat is found during compilation which will result in error during compile time.
  However keep in mind that since the deprecation attribute is not supported on all compilers,
  this is expected to fail during push workflows.


**NOTE:** while this is only an initial milestone. We might also consider
using the *_s implementation provided by the C11 Extensions (however not
yet widly supported). I would also suggest to start
looking at static code analyzers to track unsafe use cases.
For example LLVM clang checker supports security.insecureAPI.DeprecatedOrUnsafeBufferHandling
which can help locate unsafe function usage.
https://clang.llvm.org/docs/analyzer/checkers.html#security-insecureapi-deprecatedorunsafebufferhandling-c
The main reason not to onboard it at this stage is that the alternative
excepted by clang is to use the C11 extensions which are not always
supported by stdlib.
2022-07-18 10:56:26 +03:00
Valentino Geron
82b8203555
remove boolean usage and use 0/1 instead (#10997)
If we do not use jemalloc (mostly with valgrind) and use an old compiler that does not support C11
we will get compilation error

Co-authored-by: Valentino Geron <valentino@redis.com>
2022-07-17 18:28:38 +03:00
Guy Korland
587fc9ce76
Set RedisModule_StringCompare input args as const (#10996) 2022-07-17 13:53:48 +03:00
Madelyn Olson
3abdec9969
Fix cluster hostnames test causing failover while running valgrind (#10991)
In the newly added cluster hostnames test, the primary is failing over during the reboot
for valgrind so we are validating the wrong node. This change just sets the replica to
prevent taking over, which seems to fix the test.

We could have also set the timeout higher, but it slows down the test.
2022-07-17 09:57:34 +03:00
Wen Hui
2d3240f31b
Add optional for FCALL and FCALL_RO command json file (#10988)
According to the Redis functions documentation, FCALL command format could be
FCALL function_name numberOfKeys [key1, key2, key3.....] [arg1, arg2, arg3.....]

So in the json file of fcall and fcall_ro, we should add optional for key and arg part.
Just like EVAL...

Co-authored-by: Binbin <binloveplay1314@qq.com>
2022-07-17 09:40:07 +03:00
Valentino Geron
847cdca151
Add an option to specify multiple skip files using --skipfile (#10975)
`--skipfile` can be repeated.
For example: ./runtests --skipfile file1.txt --skipfile file2.txt

Co-authored-by: Valentino Geron <valentino@redis.com>
2022-07-17 08:47:35 +03:00
Oran Agra
599e59ebc5
Avoid valgrind fishy value warning on corrupt restore payloads (#10937)
The corrupt dump fuzzer uncovered a valgrind warning saying:
```
==76370== Argument 'size' of function malloc has a fishy (possibly negative) value: -3744781444216323815
```
This allocation would have failed (returning NULL) and being handled properly by redis (even before this change), but we also want to silence the valgrind warnings (which are checking that casting to ssize_t produces a non-negative value).

The solution i opted for is to explicitly fail these allocations (returning NULL), before even reaching `malloc` (which would have failed and return NULL too).

The implication is that we will not be able to support a single allocation of more than 2GB on a 32bit system (which i don't think is a realistic scenario).
i.e. i do think we could be facing cases were redis consumes more than 2gb on a 32bit system, but not in a single allocation.

The byproduct of this, is that i dropped the overflow assertions, since these will now lead to the same OOM panic we have for failed allocations.
2022-07-13 09:14:38 +03:00
Binbin
20af95a99f
Add range check for server port in redis-cli/benchmark (#9854)
Validating inputs ahead of time, to give the end user a slightly more useful error.
2022-07-12 20:32:14 -07:00
Madelyn Olson
8a4e3bcd8d
Cluster test improvements (#10920)
* Restructured testing to allow running cluster tests easily as part of the normal testing
2022-07-12 10:41:29 -07:00
Wen Hui
8221d48165
Normalize the style of help information with other documentation (#10965) 2022-07-12 09:56:02 -07:00
jimgreen2013
53e7de205f
Simplify arithmetic expression on LP_REPLACE case in lpinsert (#6327)
Remove unnecessary variable name.
2022-07-12 09:24:59 -07:00
Binbin
693acc0114
Trying to fix cluster test (#10963)
#10942 break the new test added in #10449
```
Testing unit: 29-slot-migration-response.tcl
Cluster Join and auto-discovery test: FAILED: Cluster failed to join into a full mesh.
```

It looks like we need to wait for the cluster in 28 to become stable.
2022-07-11 15:21:35 +03:00
Oran Agra
b4568fc78a
update help.h (#10961) 2022-07-11 12:36:03 +03:00
Binbin
35e8ae3eb5
Add cluster-port support to redis-cli --cluster (#10344)
In #9389, we add a new `cluster-port` config and make cluster bus port configurable,
and currently redis-cli --cluster create/add-node doesn't support with a configurable `cluster-port` instance.
Because redis-cli uses the old way (port + 10000) to send the `CLUSTER MEET` command.

Now we add this support on redis-cli `--cluster`, note we don't need to explicitly pass in the
`cluster-port` parameter, we can get the real `cluster-port` of the node in `clusterManagerNodeLoadInfo`,
so the `--cluster create` and `--cluster add-node` interfaces have not changed.

We will use the `cluster-port` when we are doing `CLUSTER MEET`, also note that `CLUSTER MEET` bus-port
parameter was added in 4.0, so if the bus_port (the one in redis-cli) is 0, or equal (port + 10000),
we just call `CLUSTER MEET` with 2 arguments, using the old form.

Co-authored-by: Madelyn Olson <34459052+madolson@users.noreply.github.com>
2022-07-11 11:23:31 +03:00
Binbin
1e85b89aef
Add --check-system in redis-server usage (#10960) 2022-07-11 08:31:39 +03:00
Madelyn Olson
e6a1b2ea95
Fix crash during handshake and cluster shards call (#10942)
* Fix an engine crash when there are nodes in handshaking and a user calls cluster shards
2022-07-10 22:00:44 -07:00
Madelyn Olson
1209dc2277
Only print ACL syntax errors once and include command names in errors (#10922)
* Only print ACL syntax errors once and include command names in errors
2022-07-09 21:02:22 -07:00
Binbin
8203461120
Fix some outdated comments and some typo (#10946)
* Fix some outdated comments and some typo
2022-07-06 20:31:59 -07:00
adasarpan404
0a2e51f9ae
Renaming conduct to code of conduct and contributing files to .md (#10941)
CONTRIBUTING to get better formatting
CONDUCT also because github doesn't seem recognize the code of conduct page

Co-authored-by: Oran Agra <oran@redislabs.com>
2022-07-06 11:58:44 +03:00
Binbin
0132ed7544
Add pubsubshard_channels field in INFO STATS (#10929)
We already have `pubsub_channels` and `pubsub_patterns`
in INFO stats, now add `pubsubshard_channels` (symmetry).

Sharded pubsub was added in #8621
2022-07-06 09:50:08 +03:00
Yossi Gottlieb
45ae605332
TLS: Notify clients on connection shutdown. (#10931)
Use SSL_shutdown(), in a best-effort manner, when closing a TLS
connection. This change better supports OpenSSL 3.x clients that will
not silently ignore the socket-level EOF.
2022-07-05 08:41:17 +03:00
Harkrishn Patro
9bcdd1537e
Avoid double multiplication of alloc_count (#10934) 2022-07-04 10:09:27 -07:00
Wen Hui
f620e6ac73
Add tests for error messages during slot migrations (#10449)
* Add tests for error messages during slot migrations

Co-authored-by: Ubuntu <lucas.guang.yang1@huawei.com>
Co-authored-by: Madelyn Olson <madelyneolson@gmail.com>
2022-07-04 10:31:12 -05:00
Harkrishn Patro
a3704d4e87
Optimize number of realloc syscall during multi/exec flow (#10921)
## Issue
During the MULTI/EXEC flow, each command gets queued until the `EXEC`
command is received and during this phase on every command queue, a
`realloc` is being invoked. This could be expensive based on the realloc
behavior (if copy to a new memory location). 


## Solution
In order to reduce the no. of syscall, couple of optimization I've used.

1. By default, reserve memory for atleast two commands. `MULTI/EXEC` for a
single command doesn't have any significance. Hence, I believe customer wouldn't use it.
2. For further reservation, increase the memory allocation in exponent growth (power of 2).
This reduces the no. of `realloc` call from `N` to `log(N)` times.

## Other changes:

* Include multi exec queued command array in client memory consumption calculation
(affects client eviction too)
2022-07-04 09:47:34 +03:00
Qu Chen
33b7ff387c
Unlock cluster config file upon server shutdown. (#10912)
Currently in cluster mode, Redis process locks the cluster config file when
starting up and holds the lock for the entire lifetime of the process.
When the server shuts down, it doesn't explicitly release the lock on the
cluster config file. We noticed a problem with restart testing that if you shut down
a very large redis-server process (i.e. with several hundred GB of data stored),
it takes the OS a while to free the resources and unlock the cluster config file.
So if we immediately try to restart the redis server process, it might fail to acquire
the lock on the cluster config file and fail to come up.

This fix explicitly releases the lock on the cluster config file upon a shutdown rather
than relying on the OS to release the lock, which is a cleaner and safer approach to
free up resources acquired.
2022-07-04 09:38:19 +03:00
Harkrishn Patro
0ab885a685
Account sharded pubsub channels memory consumption (#10925)
Account sharded pubsub channels memory consumption in client memory usage
computation to accurately evict client based on the set threshold for `maxmemory-clients`.
2022-07-04 09:18:57 +03:00
Binbin
679344a2b0
Set aof rewrite status in some backgroundRewriteDoneHandler errors (#10923)
We should also set aof_lastbgrewrite_status to C_ERR on these
errors. Because aof rewrite did fail, and we did not finish the
manifest update. Also maintain the stat_aofrw_consecutive_failures.
2022-07-03 15:36:42 +03:00
Yossi Gottlieb
0b645d6319
Fix TLS issues with large replies (#10909)
This problem was introduced by 496375f and seems to more easily reproduce on macOS since OpenSSL writes more frequently return with EAGAIN.
2022-07-03 13:35:58 +03:00
Yossi Gottlieb
69d5576832
Fix TLS tests on newer tcl-tls/OpenSSL. (#10910)
Before this commit, TLS tests on Ubuntu 22.04 would fail as dropped
connections result with an ECONNABORTED error thrown instead of an empty
read.
2022-07-03 13:34:14 +03:00
Binbin
2ab6767744
Always set server.aof_last_write_errno in aof write error (#10917)
The `can_log` variable prevents us from outputting too
many error logs. But it should not include the modification
of server.aof_last_write_errno.

We are doing this because:
1. In the short write case, we always set aof_last_write_errno
to ENOSPC, we don't care the `can_log` flag.

2. And we always set aof_last_write_status to C_ERR in aof write
error (except for FSYNC_ALWAYS, we exit). So there may be a chance
that `aof_last_write_errno` is not right.

An innocent bug or just a code cleanup.
2022-07-03 08:34:39 +03:00
Binbin
35e836c26d
Add SENTINEL command flag to CLIENT/COMMANDS subcommands (#10904)
This was harmless because we marked the parent command
with SENTINEL flag. So the populateCommandTable was ok.
And we also don't show the flag (SENTINEL and ONLY-SENTNEL)
in COMMAND INFO.

In this PR, we also add the same CMD_SENTINEL and CMD_ONLY_SENTINEL
flags check when populating the sub-commands.
so that in the future it'll be possible to add some sub-commands to sentinel or sentinel-only but not others.
2022-06-30 16:32:40 +03:00
Wen Hui
51da5c3dde
Fix CLUSTER RESET command argument number issue (#10898)
Fix regression of CLUSTER RESET command in redis 7.0.

cluster reset command format is:
CLUSTER RESET [ HARD | SOFT]

According to the cluster reset command doc and codes, the third argument is optional, so
the arity in json file should be -2 instead of 3.

Add test to verify future regressions with RESET and RESET SOFT that were not covered.

Co-authored-by: Ubuntu <lucas.guang.yang1@huawei.com>
Co-authored-by: Oran Agra <oran@redislabs.com>
Co-authored-by: Binbin <binloveplay1314@qq.com>
2022-06-29 08:17:00 +03:00
jonnyomerredis
35c2ee8716
Add sharded pubsub keychannel count to client info (#10895)
When calling CLIENT INFO/LIST, and in various debug prints, Redis is printing
the number of pubsub channels / patterns the client is subscribed to.
With the addition of sharded pubsub, it would be useful to print the number of
keychannels the client is subscribed to as well.
2022-06-28 10:11:17 +03:00
Tian
069b30a2b3
A minor refinement to clusterbus extension estlen (#10902) 2022-06-27 20:42:55 -07:00
Viktor Söderqvist
6af021007a
Add missing REDISMODULE_CLIENTINFO_INITIALIZER (#10885)
The module API docs mentions this macro, but it was not defined (so no one could have used it).

Instead of adding it as is, we decided to add a _V1 macro, so that if / when we some day extend this struct,
modules that use this API and don't need the extra fields, will still use the old version
and still be compatible with older redis version (despite being compiled with newer redismodule.h)
2022-06-27 08:29:05 +03:00
RinChanNOW!
2854637385
Support conversion between RedisModuleString and unsigned long long (#10889)
Since the ranges of `unsigned long long` and `long long` are different, we cannot read an
`unsigned long long` integer from a `RedisModuleString` by `RedisModule_StringToLongLong` . 

So I added two new Redis Module APIs to support the conversion between these two types:
* `RedisModule_StringToULongLong`
* `RedisModule_CreateStringFromULongLong`

Signed-off-by: RinChanNOWWW <hzy427@gmail.com>
2022-06-26 15:02:52 +03:00
Binbin
d443e312ad
redis-server command line arguments allow passing config name and value in the same arg (#10866)
This commit has two topics.

## Passing config name and value in the same arg
In #10660 (Redis 7.0.1), when we supported the config values that can start with `--` prefix (one of the two topics of that PR),
we broke another pattern: `redis-server redis.config "name value"`, passing both config name
and it's value in the same arg, see #10865

This wasn't a intended change (i.e we didn't realize this pattern used to work).
Although this is a wrong usage, we still like to fix it.

Now we support something like:
```
src/redis-server redis.conf "--maxmemory '700mb'" "--maxmemory-policy volatile-lru" --proc-title-template --my--title--template --loglevel verbose
```

## Changes around --save
Also in this PR, we undo the breaking change we made in #10660 on purpose.
1. `redis-server redis.conf --save --loglevel verbose` (missing `save` argument before anotehr argument).
    In 7.0.1, it was throwing an wrong arg error.
    Now it will work and reset the save, similar to how it used to be in 7.0.0 and 6.2.x.
3. `redis-server redis.conf --loglevel verbose --save` (missing `save` argument as last argument).
    In 6.2, it did not reset the save, which was a bug (inconsistent with the previous bullet).
    Now we will make it work and reset the save as well (a bug fix).
2022-06-26 14:36:39 +03:00
Viktor Söderqvist
6272ca609e
Add RM_SetClientNameById and RM_GetClientNameById (#10839)
Adding Module APIs to let the module read and set the client name of an arbitrary connection.
2022-06-26 14:34:59 +03:00
Binbin
d96cf3639a
Sync argv_len var back after command call in execCommand (#10900)
This is harmless, we only restore mstate to make sure we
free the right pointer in freeClientMultiState, but it'll
be nicer to also sync that argv_len var back.
2022-06-26 12:32:34 +03:00
Elvina Yakubova
e2cf386765
Replace regular array to array of structs to get rid of false sharing (#10892)
There are a lot of false sharing cache misses in line 4013 inside getIOPendingCount function.
The reason is that elements of io_threads_pending array access the same cache line from different
threads, so it is better to represent it as an array of structures with fields aligned to cache line size.
This change should improve performance (in particular, it affects the latency metric, we saw up to 3% improvement).
2022-06-26 08:39:30 +03:00
Steve Lorello
a64b29485d
changing min,max in ZRANGE -> start stop (#10097)
In 6.2.0 with the introduction of the REV subcommand in ZRANGE, there was a semantic shift in the arguments of ZRANGE when the REV sub-command is executed. Without the sub-command `min` and `max` (the old names of the arguments) are appropriate because if you put the min value and the max value in everything works fine.

```bash
127.0.0.1:6379> ZADD myset 0 foo
(integer) 1
127.0.0.1:6379> ZADD myset 1 bar
(integer) 1
127.0.0.1:6379> ZRANGE myset 0 inf BYSCORE
1) "foo"
2) "bar"
``` 

However - if you add the `REV` subcommand, ordering the arguments `min` `max` breaks the command:

```bash
127.0.0.1:6379> ZRANGE myset 0 inf BYSCORE REV
(empty array)
```

why? because `ZRANGE` with the `REV` sub-command is expecting the `max` first and the `min` second (because it's a reverse range like `ZREVRANGEBYSCORE`):

```bash
127.0.0.1:6379> ZRANGE myset 0 inf BYSCORE REV
(empty array)
```
2022-06-25 19:02:20 +03:00
WuYunlong
64205345bc
migrateGetSocket() cleanup.. (#5546)
I think parameter c is only useful to get client reply.
Besides, other commands' host and port parameters may not be the at index 1 and 2.
2022-06-23 18:41:32 +03:00
Binbin
755b51a42c
When dirCreateIfMissing or openNewIncrAofForAppend fail, set aof_lastbgrewrite_status to err (#10775)
It will be displayed in the `aof_last_bgrewrite_status`
field of the INFO command.
2022-06-23 18:40:20 +03:00
(╯°□°)╯︵ uᴉǝssnH ɐɟɐʇsoW
c52922e1d9
command prompt help: add stdin config usage (#6313)
Signed-off-by: Mostafa Hussein <mostafa.hussein91@gmail.com>
2022-06-23 18:37:42 +03:00
judeng
d2405b9b6b
fix benchmark failure in daily test with TLS (#10896)
The new test added in #10891 can fail with a different error.
see comment in networking.c saying
```c
        /* That's a best effort error message, don't check write errors.
         * Note that for TLS connections, no handshake was done yet so nothing
         * is written and the connection will just drop. */
```
2022-06-23 18:19:36 +03:00
Binbin
aabce8932a
Add bus_port argument in cluster-meet.json (#10304)
In `CLUSTER MEET`, bus-port argument was added in 11436b1.
For cluster announce ip / port implementation, part of the
4.0-RC1.

And in #9389, we add a new cluster-port config and make
cluster bus port configurable, part of the 7.0-RC1.
2022-06-23 07:56:25 +03:00
judeng
49876158cc
fix redis-benchmark's bug: check if clients are created successfully in idle mode (#10891)
my maxclients config:
```
redis-cli config get maxclients
1) "maxclients"
2) "4064"
```

Before this bug was fixed, creating 4065 clients appeared to be successful, but only 4064 were actually created```
```
./redis-benchmark -c 4065 -I
Creating 4065 idle connections and waiting forever (Ctrl+C when done)
cients: 4065
```

now :
```
./redis-benchmark -c 4065 -I
Creating 4065 idle connections and waiting forever (Ctrl+C when done)
Error from server: ERR max number of clients reached

./redis-benchmark -c 4064 -I
Creating 4064 idle connections and waiting forever (Ctrl+C when done)
clients: 4064

```
2022-06-22 19:30:22 +03:00