Git Product home page Git Product logo

Comments (11)

zieckey avatar zieckey commented on August 16, 2024

Please paste the codes and give the whole steps which can produce this problem.

from evpp.

jvalenciag avatar jvalenciag commented on August 16, 2024

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.

zieckey avatar zieckey commented on August 16, 2024

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.

jvalenciag avatar jvalenciag commented on August 16, 2024

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.

zieckey avatar zieckey commented on August 16, 2024

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.

jvalenciag avatar jvalenciag commented on August 16, 2024

Yes I changed that as suggested, but the execution does not even reach that line, it fails in the first call.

from evpp.

zieckey avatar zieckey commented on August 16, 2024

OK, that's really weird.
Can you paste the code which can produce the problem?

from evpp.

zieckey avatar zieckey commented on August 16, 2024

Any update?

from evpp.

jvalenciag avatar jvalenciag commented on August 16, 2024

Now I updated to v0.4.0 and the problem didn't happen again until now.

from evpp.

jvalenciag avatar jvalenciag commented on August 16, 2024

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.

zieckey avatar zieckey commented on August 16, 2024

Glad to here that

from evpp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.