qicosmos / rest_rpc

modern C++(C++11), simple, easy to use rpc framework
MIT License
1.66k stars 365 forks source link

bug #93

Closed lemon19900815 closed 1 year ago

lemon19900815 commented 1 year ago

inline std::string get_error_msg(string_view result) { rpc_service::msgpack_codec codec; auto tp = codec.unpack<std::tuple<int, std::string>>(result.data(), result.size()); return std::get<1>(tp); }

template inline T as(string_view result) { if (has_error(result)) { throw std::logic_error(get_error_msg(result)); }

return get_result(result); }

如果result为空,抛出异常前会获取get_error_msg信息,解码的时候会crashdump

qicosmos commented 1 year ago

谢谢报告,稍后看一下。

lemon19900815 commented 1 year ago

error 就是这两处,你上面处理1处理的逻辑是正确的,处理2忘记对空的err_msg进行判断。

qicosmos commented 1 year ago

是的,如果方便的话,你可以提一个pr,把漏掉的这一行加上。

lemon19900815 commented 1 year ago

ok。关于异步调用的测试用例代码test_callback中,使用async_call指定超时时间为100ms,并不能通过单元测试,我调查了好长一段时间才发现是服务端的代码在async_echo的时候休眠了1s,我认为它不应该留在测试代码中。

qicosmos commented 1 year ago

可以去掉休眠。

lemon19900815 commented 1 year ago

你好,大佬!我这里还有1个问题请教:我单独测试test_ssl接口时,如果我不等待异步操作完成,则客户端和服务端有极大的概率死掉,它们同时挂在一个地方。 error stack

qicosmos commented 1 year ago

你说的是这一行吗:https://github.com/qicosmos/rest_rpc/blob/master/examples/client/main.cpp#L613 想及时完成测试的话,可以考虑通过promise去同步等待一下,保证异步返回完成。 还有另外一个方法就是lambda捕获智能指针,保证异步回调的安全性,否则回调回来client都析构函了,造成访问释放的对象和数据肯定会出错。

lemon19900815 commented 1 year ago

是的,就是这行!但是按照道理来讲,服务端不应该挂掉吧?

qicosmos commented 1 year ago

是的,这里可以改进一下,我晚点修一下。

lemon19900815 commented 1 year ago

找到个同源的,purecpp也是你维护的!https://blog.csdn.net/weixin_33321637/article/details/112124876

lemon19900815 commented 1 year ago

是的,如果方便的话,你可以提一个pr,把漏掉的这一行加上。

faa5c8d

qicosmos commented 1 year ago

done

qicosmos commented 1 year ago

done