rmsacks opened a new issue, #2993: URL: https://github.com/apache/kvrocks/issues/2993
### Search before asking - [x] I had searched in the [issues](https://github.com/apache/kvrocks/issues) and found no similar issues. ### Version OS: Debian GNU/Linux 12 (bookworm) Kvrocks: unstable (fa5f77f1500c79f414c9bdfdaa9580ce3a1a8cb9) ### Minimal reproduce step Start Kvrocks with the default build and default config: ``` $ ./build/kvrocks -c ./kvrocks.conf ``` Use the `XINFO STREAM` command without any arguments: ``` $ redis-cli -p 6666 127.0.0.1:6666> XINFO STREAM Error: Server closed the connection (2.71s) not connected> ``` ### What did you expect to see? I expected an "Unknown subcommand or wrong number of arguments" error to be returned, since that is what happens when the `XINFO GROUPS` and `XINFO CONSUMERS` commands are use without the correct number of arguments. For example: ``` $ redis-cli -p 6666 127.0.0.1:6666> XINFO GROUPS (error) ERR Unknown subcommand or wrong number of arguments 127.0.0.1:6666> XINFO CONSUMERS (error) ERR Unknown subcommand or wrong number of arguments 127.0.0.1:6666> ``` ### What did you see instead? The client connection gets disconnected (as show in the reproducible example) and the server process crashes with the following stack trace: ``` $ ./build/kvrocks -c ~/kvrocks-test.conf [2025-05-24T18:34:14.385048+00:00][W][server.cc:1874] [server] Increased maximum number of open files to 18224 (it's originally set to 1024) terminate called after throwing an instance of 'std::length_error' what(): basic_string::append [2025-05-24T18:34:23.558798+00:00][E][signal_util.h:34] Ooops! Apache Kvrocks unstable (commit fa5f77f1500c) got signal: Aborted (6) [2025-05-24T18:34:27.529365+00:00][E][signal_util.h:41] Stack trace (most recent call first): #0 0x000055ac61f51ed1 in SegvHandler at /media/storage/share/kvrocks/src/cli/signal_util.h:35 #1 0x00007fbad386504f in __sigaction at /lib/x86_64-linux-gnu/libc.so.6 #2 0x00007fbad38b3eec in pthread_key_delete at /lib/x86_64-linux-gnu/libc.so.6 #3 0x00007fbad3864fb1 in gsignal at /lib/x86_64-linux-gnu/libc.so.6 #4 0x00007fbad384f471 in abort at /lib/x86_64-linux-gnu/libc.so.6 #5 0x000055ac61bf06af in __gnu_cxx::__verbose_terminate_handler() [clone .cold] at vterminate.o #6 0x000055ac626d4c49 in __cxxabiv1::__terminate(void (*)()) at /media/storage/share/kvrocks/build/kvrocks #7 0x000055ac626d4cb4 in std::terminate() at /media/storage/share/kvrocks/build/kvrocks #8 0x000055ac626d4e07 in __cxa_throw at /media/storage/share/kvrocks/build/kvrocks #9 0x000055ac61bf2003 in std::__throw_length_error(char const*) at /media/storage/share/kvrocks/build/kvrocks #10 0x000055ac61eaa913 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_check_length(unsigned long, unsigned long, char const*) const at /usr/include/c++/12/bits/basic_string.h:393 #11 0x000055ac61eaa965 in redis::Database::AppendNamespacePrefix[abi:cxx11](rocksdb::Slice const&) at /media/storage/share/kvrocks/src/storage/redis_db.cc:521 #12 0x000055ac61dc4d0d in redis::Stream::GetStreamInfo(engine::Context&, rocksdb::Slice const&, bool, unsigned long, redis::StreamInfo*) at /media/storage/share/kvrocks/src/types/redis_stream.cc:1206 #13 0x000055ac61dcbcc4 in redis::CommandXInfo::Execute(engine::Context&, Server*, redis::Connection*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*) at /media/storage/share/kvrocks/src/commands/cmd_stream.cc:704 #14 0x000055ac61e7b52a in redis::Connection::ExecuteCommand(engine::Context&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, redis::Commander*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*) at /media/storage/share/kvrocks/src/server/redis_connection.cc:363 #15 0x000055ac61e7ea43 in redis::Connection::ExecuteCommands(std::deque<std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, std::allocator<std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > >*) at /media/storage/share/kvrocks/src/server/redis_connection.cc:561 #16 0x000055ac61d0ca4a in redis::Connection::OnRead(bufferevent*) at /media/storage/share/kvrocks/src/server/redis_connection.cc:96 #17 0x000055ac6254341d in bufferevent_run_deferred_callbacks_unlocked at /media/storage/share/kvrocks/build/_deps/libevent-src/bufferevent.c:208 #18 0x000055ac6254958c in event_process_active_single_queue at /media/storage/share/kvrocks/build/_deps/libevent-src/event.c:1720 #19 0x000055ac62549f36 in event_process_active at /media/storage/share/kvrocks/build/_deps/libevent-src/event.c:1783 #20 0x000055ac61e99dfb in Worker::Run(std::thread::id) at /media/storage/share/kvrocks/src/server/worker.cc:316 #21 0x000055ac627542e2 in execute_native_thread_routine at thread.o #22 0x00007fbad38b21f4 in pthread_condattr_setpshared at /lib/x86_64-linux-gnu/libc.so.6 #23 0x00007fbad393289b in __xmknodat at /lib/x86_64-linux-gnu/libc.so.6 [2025-05-24T18:34:27.529686+00:00][E][signal_util.h:42] It would be greatly appreciated if you could submit this crash to https://github.com/apache/kvrocks/issues along with the stacktrace above, logs and any relevant information. Aborted (core dumped) ``` ### Anything Else? I believe the issue is that the function `redis::CommandXInfo::Parse` only requires that an `XINFO STREAM` command [has at least two total arguments](https://github.com/apache/kvrocks/blob/fa5f77f1500c79f414c9bdfdaa9580ce3a1a8cb9/src/commands/cmd_stream.cc#L676) while `redis::CommandXInfo::getStreamInfo` will [unconditionally try to use the third argument](https://github.com/apache/kvrocks/blob/fa5f77f1500c79f414c9bdfdaa9580ce3a1a8cb9/src/commands/cmd_stream.cc#L726), even if there are only two. Applying the following patch seems to fix the issue in my testing: ```diff --- a/src/commands/cmd_stream.cc +++ b/src/commands/cmd_stream.cc @@ -673,7 +673,7 @@ class CommandXInfo : public Commander { public: Status Parse(const std::vector<std::string> &args) override { auto val = util::ToLower(args[1]); - if (val == "stream" && args.size() >= 2) { + if (val == "stream" && args.size() >= 3) { subcommand_ = "stream"; if (args.size() > 3 && util::ToLower(args[3]) == "full") { ``` ``` $ ./build-fixed/kvrocks -c ./kvrocks.conf ``` ``` $ redis-cli -p 6666 127.0.0.1:6666> XINFO STREAM (error) ERR Unknown subcommand or wrong number of arguments 127.0.0.1:6666> ``` ### Are you willing to submit a PR? - [x] I'm willing to submit a PR! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
