Comments (11)
Please paste the codes and give the whole steps which can produce this problem.
from evpp.
It is kind of weird because it only happens when I run on a centOS 7 server with gcc 5.3.1.
I am running a tcp server with this message callback.
void OnPBMessage(PBMessageCallback<C> callback, const evpp::TCPConnPtr &conn, evpp::Buffer *buf) {
auto ctx = *evpp::any_cast<std::shared_ptr<pbTCPReadCtx> >(&conn->context());
LOG_TRACE << "New message from " << conn->AddrToString();
//buf->
LOG_TRACE << "Data size:" << buf->size() ; // <==== This call causes the error
while (buf->size() > header_len) {
if (!ctx->reading) {
google::protobuf::io::CodedInputStream coded_input(
(const google::protobuf::uint8 *) buf->data(), (int) header_len);
coded_input.ReadVarint32(&ctx->size);
ctx->full_size = header_len + ctx->size;
ctx->reading = true;
LOG_TRACE << "first read msg_size:" << ctx->full_size;
}
if (buf->size() < ctx->full_size) {
LOG_TRACE << "waiting for more data";
// need to read more data
return;
}
LOG_TRACE << "reading full msg";
C payload;
google::protobuf::io::CodedInputStream coded_input(
(const google::protobuf::uint8 *) buf->data(), (int) ctx->full_size);
coded_input.ReadVarint32(&ctx->size);
payload.ParseFromCodedStream(&coded_input);
buf->Skip(ctx->full_size);
ctx->reading = false;
callback(conn, std::move(payload));
}
}
from evpp.
That's so weird. I can't get what's wrong with it.
Suggest that you can use LOG_TRACE to print the value of Buffer::write_index_
and Buffer::read_index_
in Buffer::lenght()
. Showing as bellow:
// length returns the number of bytes of the unread portion of the buffer
size_t length() const {
+ LOG_TRACE << "Buffer::length write_index=" << write_index_ << " read_index_=" << read_index_;
assert(write_index_ >= read_index_);
return write_index_ - read_index_;
}
And we need to be very careful to use Buffer::data() instead of Buffer::Next(size_t)
. Try the codes bellow:
void OnPBMessage(PBMessageCallback<C> callback, const evpp::TCPConnPtr &conn, evpp::Buffer *buf) {
auto ctx = *evpp::any_cast<std::shared_ptr<pbTCPReadCtx>>(&conn->context());
LOG_TRACE << "New message from " << conn->AddrToString();
//buf->
LOG_TRACE << "Data size:" << buf->size(); // <==== This call causes the error
while (buf->size() > header_len) {
if (!ctx->reading) {
evpp::Slice data = buf->Next(header_len);
LOG_TRACE << "header_len=" << header_len << " readn=" << data.size();
google::protobuf::io::CodedInputStream coded_input(
(const google::protobuf::uint8 *) data.data(), (int)data.size());
coded_input.ReadVarint32(&ctx->size);
ctx->full_size = header_len + ctx->size;
ctx->reading = true;
LOG_TRACE << "first read msg_size:" << ctx->full_size;
}
if (buf->size() < ctx->full_size) {
LOG_TRACE << "waiting for more data";
// need to read more data
return;
}
LOG_TRACE << "reading full msg";
C payload;
evpp::Slice data = buf->Next(ctx->full_size);
LOG_TRACE << "full_size=" << ctx->full_size << " readn=" << data.size();
google::protobuf::io::CodedInputStream coded_input(
(const google::protobuf::uint8 *) data.data(), (int)data.size());
coded_input.ReadVarint32(&ctx->size);
payload.ParseFromCodedStream(&coded_input);
ctx->reading = false;
callback(conn, std::move(payload));
}
}
from evpp.
It always happens when the first message arrives.
some samples:
Buffer::length write_index=32417664 read_index_=32417944
Buffer::length write_index=9914240 read_index_=9914520
Buffer::length write_index=32868224 read_index_=32868504
The difference is always -280
.
On the client side I am getting :
E0422 22:56:23.591197 439938 connector.cc:161] status=kConnecting fd=15 errno=111 Connection refused this= 0x7faa88000a20 use_count=5
So this is not even a message it is a connection attempt.
from evpp.
Do you use buf->Next(size_t)
to replace buf->data()
? And can you paste the whole program (maybe it is another small program) to reproduce the problem?
from evpp.
Yes I changed that as suggested, but the execution does not even reach that line, it fails in the first call.
from evpp.
OK, that's really weird.
Can you paste the code which can produce the problem?
from evpp.
Any update?
from evpp.
Now I updated to v0.4.0 and the problem didn't happen again until now.
from evpp.
I forgot to mention that the problem happened running my program in two different hosts, the server(receiving data) running in centos 7 and client running centos 6, perhaps it could be related.
Now I updated the client to centos 7 and evpp to v0.4.0 and the problem didn't happened again until now.
from evpp.
Glad to here that
from evpp.
Related Issues (20)
- whether evpp::TCPConnPtr is thread safe or not?
- MFC程序下 eventloop直接报错
- 有实现SSL TCP通信的吗
- EventLoop.Run函数底层会创建很多线程嘛 HOT 1
- Evpp failed to build with error LNK1181 on MSVC
- is this project still active? HOT 1
- example_evpphttp_server, server not init HOT 1
- The echo UDP server example does not compile against package installed by vcpkg. HOT 3
- evpp支持同时监听ipv6和ipv4吗?支持的话如何开启?
- Potential memory leak in benchmark/throughput/libevent/client.c
- Potential memory leak in benchmark/throughput/libevent/server.c
- Potential memory leak in benchmark/http/libevent/libevent_http_bench.c
- Potential memory leak in benchmark/throughput/libevent/client.c
- Potential memory leak in benchmark/throughput/libevent/server.c
- Potential memory leak in benchmark/http/libevent/libevent_http_bench.c
- Potential memory leak in apps/evmc/extract_vbucket_conf.cc HOT 1
- Potential memory leak in test/evhttp_client_test.cc HOT 1
- ASan heap-use-after-free in tcpserver tests
- TCPServer 的 thread_num 有什么作用 ? ,为什么要建立多个 EventLoopThreadPool ? 1 和 4 有什么区别吗? HOT 2
- Potential Null pointer dereference in request.cc
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from evpp.