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

Run for some mins, there is a segmentation error #17

Closed
jchen357 opened this issue Oct 10, 2018 · 5 comments
Closed

Run for some mins, there is a segmentation error #17

jchen357 opened this issue Oct 10, 2018 · 5 comments

Comments

@jchen357
Copy link

Here is my file

main.cc

#include <influxdb_raw_db_utf8.h>
#include <influxdb_simple_api.h>
#include <influxdb_line.h>
#include <influxdb_simple_async_api.h>
#include "influx.h"

#include <iostream>
#include <thread>
#include <chrono>
#include <time.h>
#include <unistd.h>
#include <sys/time.h>

using namespace influxdb::api;
using namespace std;

int main(int argc, char *argv[]) {
	try {
		int keyNum = 0;

		influxdb::async_api::simple_db async_api("http://10.11.12.17:8086", "bluewhale");

		struct timeval begin;
		gettimeofday(&begin, NULL);

		while (1) {
			struct timeval tv,td;
			gettimeofday(&tv, NULL);
			long time = (long long) (tv.tv_sec) * 1000000000 + tv.tv_usec * 1000;

			influxdb::api::key_value_pairs tags;
			influxdb::api::key_value_pairs fields;
			string g_app_name = "test";
			string rankID = "1";
			std::cout << "key num: " << keyNum << std::endl;
			tags.add("appName", g_app_name);
			tags.add("svrID", rankID);
			fields.add("value", keyNum);
			xflow::Influx::Get()->insert(line("t_lr_key", tags, fields));

			gettimeofday(&td, NULL);
			std::cout << "cost time " << (td.tv_sec - tv.tv_sec) * 1000000 + (td.tv_usec - tv.tv_usec) << std::endl;

			std::cout << "current time " << (td.tv_sec - begin.tv_sec) / 60 << std::endl << std::endl;
			keyNum++;
			sleep(1);
		}

	}
	catch (std::exception const &e) {
		std::cerr << e.what() << std::endl;
	}

	return 0;
}

gdb info

@d-led
Copy link
Owner

d-led commented Oct 10, 2018

Thanks! I'll look at it. There are important pieces of information missing: how did you compile the library and your application, e.g., which Boost version is used.

To reproduce the example, I'd probably need to know what "influx.h" and xflow::Influx::Get() are, and how the singleton is initialized. Why not try to initialize it in the scope of main?

@d-led
Copy link
Owner

d-led commented Oct 10, 2018

as you're using the async api, are you sure, you're not just running out of memory?

@d-led
Copy link
Owner

d-led commented Oct 20, 2018

reproduced the code in a branch. Will wait for a couple of minutes. I don't see anything suspicious. You're not pushing too many points either. I'll try shutting down the database after a while to see what happens

@d-led
Copy link
Owner

d-led commented Oct 20, 2018

when there's no connectivity to the DB the program terminates

$ bin/macosx/gmake/x64/Debug/demo 
key num: 0
cost time 172
current time 0

Trace/BPT trap: 5

Process 3267 launched: '/Users/..../src/influxdb-cpp-rest/bin/macosx/gmake/x64/Debug/demo' (x86_64)
key num: 0
cost time 206
current time 0

Process 3267 stopped
* thread #2, stop reason = signal SIGTRAP
    frame #0: 0x00007fff6eb46b66 libsystem_kernel.dylib`__pthread_kill + 10
libsystem_kernel.dylib`__pthread_kill:
->  0x7fff6eb46b66 <+10>: jae    0x7fff6eb46b70            ; <+20>
    0x7fff6eb46b68 <+12>: movq   %rax, %rdi
    0x7fff6eb46b6b <+15>: jmp    0x7fff6eb3dae9            ; cerror_nocancel
    0x7fff6eb46b70 <+20>: retq   
Target 0: (demo) stopped.
(lldb) bt
* thread #2, stop reason = signal SIGTRAP
  * frame #0: 0x00007fff6eb46b66 libsystem_kernel.dylib`__pthread_kill + 10
    frame #1: 0x00007fff6ed11080 libsystem_pthread.dylib`pthread_kill + 333
    frame #2: 0x00007fff6ea546fe libsystem_c.dylib`raise + 26
    frame #3: 0x0000000100921ddd libcpprest.2.10.dylib`pplx::details::_ExceptionHolder::~_ExceptionHolder() + 53
    frame #4: 0x00007fff6c97d8fd libc++.1.dylib`std::__1::__shared_weak_count::__release_shared() + 43
    frame #5: 0x00000001008ff066 libcpprest.2.10.dylib`pplx::details::_Task_completion_event_impl<web::http::http_response>::~_Task_completion_event_impl() + 64
    frame #6: 0x00007fff6c97d8fd libc++.1.dylib`std::__1::__shared_weak_count::__release_shared() + 43
    frame #7: 0x00000001008fd9f6 libcpprest.2.10.dylib`web::http::client::details::request_context::~request_context() + 42
    frame #8: 0x00007fff6c97d8fd libc++.1.dylib`std::__1::__shared_weak_count::__release_shared() + 43
    frame #9: 0x0000000100a0309a libcpprest.2.10.dylib`boost::asio::detail::reactive_socket_connect_op<boost::_bi::bind_t<void, boost::_mfi::mf2<void, web::http::client::details::asio_context, boost::system::error_code const&, boost::asio::ip::basic_resolver_iterator<boost::asio::ip::tcp> >, boost::_bi::list3<boost::_bi::value<std::__1::shared_ptr<web::http::client::details::asio_context> >, boost::arg<1> (*)(), boost::_bi::value<boost::asio::ip::basic_resolver_iterator<boost::asio::ip::tcp> > > > >::do_complete(void*, boost::asio::detail::scheduler_operation*, boost::system::error_code const&, unsigned long) + 160
    frame #10: 0x000000010098ad9a libcpprest.2.10.dylib`boost::asio::detail::scheduler::do_run_one(boost::asio::detail::conditionally_enabled_mutex::scoped_lock&, boost::asio::detail::scheduler_thread_info&, boost::system::error_code const&) + 410
    frame #11: 0x00000001009e3188 libcpprest.2.10.dylib`boost::asio::detail::scheduler::run(boost::system::error_code&) + 296
    frame #12: 0x00000001009e2ff7 libcpprest.2.10.dylib`boost::asio::detail::posix_thread::func<(anonymous namespace)::threadpool_impl::add_thread()::'lambda'()>::run() + 47
    frame #13: 0x00000001009e8bc8 libcpprest.2.10.dylib`boost_asio_detail_posix_thread_function + 16
    frame #14: 0x00007fff6ed0e661 libsystem_pthread.dylib`_pthread_body + 340
    frame #15: 0x00007fff6ed0e50d libsystem_pthread.dylib`_pthread_start + 377
    frame #16: 0x00007fff6ed0dbf9 libsystem_pthread.dylib`thread_start + 13

@d-led
Copy link
Owner

d-led commented Oct 20, 2018

Now I think I can say for sure, there was an error inserting data into the DB. Added explicit waits for the cpprestsdk request tasks, catching and re-throwing errors.

Opened #18 as an open-ended follow-up reminder. Now your program should run, and in case of errors output something like:

async_api::insert failed: Failed to connect to any resolved endpoint -> Dropping 43 bytes
key num: 1
cost time 359
current time 0

@d-led d-led closed this as completed Oct 20, 2018
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

2 participants