Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys_close() error crashes server due to uncaught exception #310

Open
gusev-vitaliy opened this issue Mar 17, 2023 · 0 comments
Open

sys_close() error crashes server due to uncaught exception #310

gusev-vitaliy opened this issue Mar 17, 2023 · 0 comments

Comments

@gusev-vitaliy
Copy link

gusev-vitaliy commented Mar 17, 2023

Boost's code throw-s error, when sys_close() returns error. Due to nobody catches this exception, program crashes via abort(). Setting suppress_exceptions, doesn't solve problem.

sys_close() is called on server side when client disconnects. Error can be, for the instance, 54 'close: Connection reset by peer'

Stack:

$ lldb ./echo_server  -c echo_server.core 
(lldb) target create "./echo_server" --core "echo_server.core"
Core file 'echo_server.core' (x86_64) was loaded.
(lldb) bt
* thread #1, name = 'echo_server', stop reason = signal SIGABRT
  * frame #0: 0x0000000825d7632a libc.so.7`__sys_thr_kill + 10
    frame #1: 0x0000000825ceec74 libc.so.7`__raise + 52
    frame #2: 0x0000000825da00f9 libc.so.7`abort + 73
    frame #3: 0x0000000823e94e69 libcxxrt.so.1`___lldb_unnamed_symbol453 + 73
    frame #4: 0x0000000000247cf3 echo_server`void clmdep_asio::detail::throw_exception<std::__1::system_error>(std::__1::system_error const&) + 67
    frame #5: 0x0000000000247c7c echo_server`clmdep_asio::detail::do_throw_error(std::__1::error_code const&, char const*) + 60
    frame #6: 0x0000000000247c13 echo_server`clmdep_asio::detail::throw_error(std::__1::error_code const&, char const*) + 51
    frame #7: 0x000000000025f5fd echo_server`clmdep_asio::basic_socket<clmdep_asio::ip::tcp, clmdep_asio::stream_socket_service<clmdep_asio::ip::tcp> >::close() + 93
    frame #8: 0x000000000025f535 echo_server`rpc::detail::async_writer::close()::'lambda'()::operator()() const + 101
    frame #9: 0x000000000025f4c5 echo_server`void clmdep_asio::clmdep_asio_handler_invoke<rpc::detail::async_writer::close()::'lambda'()>(rpc::detail::async_writer::close()::'lambda'()&, ...) + 21
    frame #10: 0x000000000025f41f echo_server`void clmdep_asio_handler_invoke_helpers::invoke<rpc::detail::async_writer::close()::'lambda'(), rpc::detail::async_writer::close()::'lambda'()>(rpc::detail::async_writer::close()::'lambda'()&, rpc::detail::async_writer::close()::'lambda'()&) + 47
    frame #11: 0x000000000025f308 echo_server`clmdep_asio::detail::completion_handler<rpc::detail::async_writer::close()::'lambda'()>::do_complete(clmdep_asio::detail::task_io_service*, clmdep_asio::detail::task_io_service_operation*, std::__1::error_code const&, unsigned long) + 152
    frame #12: 0x00000000002541ee echo_server`clmdep_asio::detail::task_io_service_operation::complete(clmdep_asio::detail::task_io_service&, std::__1::error_code const&, unsigned long) + 46
    frame #13: 0x000000000025dde8 echo_server`clmdep_asio::detail::strand_service::do_complete(clmdep_asio::detail::task_io_service*, clmdep_asio::detail::task_io_service_operation*, std::__1::error_code const&, unsigned long) + 152
    frame #14: 0x00000000002541ee echo_server`clmdep_asio::detail::task_io_service_operation::complete(clmdep_asio::detail::task_io_service&, std::__1::error_code const&, unsigned long) + 46
    frame #15: 0x000000000025388e echo_server`clmdep_asio::detail::task_io_service::do_run_one(clmdep_asio::detail::scoped_lock<clmdep_asio::detail::posix_mutex>&, clmdep_asio::detail::task_io_service_thread_info&, std::__1::error_code const&) + 462
    frame #16: 0x000000000025349d echo_server`clmdep_asio::detail::task_io_service::run(std::__1::error_code&) + 221
    frame #17: 0x000000000024634e echo_server`clmdep_asio::io_service::run() + 46
    frame #18: 0x0000000000244191 echo_server`rpc::server::run() + 33
    frame #19: 0x00000000002309ca echo_server`main + 170
    frame #20: 0x0000000000230730 echo_server`_start(ap=<unavailable>, cleanup=<unavailable>) at crt1_c.c:75:7

OS: FreeBSD 13.1
clang 13.0.0

Steps to reproduce:

Use libsysclose.so (error injection wrapper):

#include <errno.h>

extern int errno;
extern int _close(int);
int close(int fd)
{
        errno = 54;
        _close(fd);
        return (-1);
}

Create libsysclose.so wrapper library

cc  sysclose.c -c -fPIC
ld --shared sysclose.o -o libsysclose.so

Run echo_server:

$ env LD_PRELOAD=./libsysclose.so ./echo_server

Run echo_client and press Ctrl-C:

$ ./echo_client
^C

@gusev-vitaliy gusev-vitaliy changed the title sys_close() error can crash server sys_close() error crashes server due to uncaught exception Mar 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant