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

Some bug in your code #10

Open
yudnkuku opened this issue Nov 26, 2018 · 1 comment
Open

Some bug in your code #10

yudnkuku opened this issue Nov 26, 2018 · 1 comment

Comments

@yudnkuku
Copy link

  • In your HttpUtil.parseHttpRequest() method:
    the variable bodyEndIndex should be bodyStartIndex + httpHeaders.contentLength + 1 rather than bodyStartIndex + httpHeaders.contentLength

  • In your Message.writePartialMessageToMessage method:
    the variable startIndexOfPartialMessage should just be endIndex + 1 rather than message.offset + endIndex.
    the variable lengthOfPartialMessage should be (message.offset + message.length) - endIndex + 1 rather than (message.offset + message.length) - endIndex

  • I got a NPE when invoking the HttpMessageReader.read().The code snippet is shown below:

Message message = this.messageBuffer.getMessage;    //the return message might be null
message.metadata = new HttpHeaders();    //the NPE occurs here

To solve the problem,I add some code in your QueueIntFlip.take() method:

        if(!flipped){
            //add this if 
            if(readPos == capacity) {
                readPos = 0;
            }
            if(readPos < writePos){
                return elements[readPos++];
            } else {
                return -1;
            }
        }
@stepfortune
Copy link

  • In your HttpUtil.parseHttpRequest() method:
    the variable bodyEndIndex should be bodyStartIndex + httpHeaders.contentLength + 1 rather than bodyStartIndex + httpHeaders.contentLength
  • In your Message.writePartialMessageToMessage method:
    the variable startIndexOfPartialMessage should just be endIndex + 1 rather than message.offset + endIndex.
    the variable lengthOfPartialMessage should be (message.offset + message.length) - endIndex + 1 rather than (message.offset + message.length) - endIndex
  • I got a NPE when invoking the HttpMessageReader.read().The code snippet is shown below:
Message message = this.messageBuffer.getMessage;    //the return message might be null
message.metadata = new HttpHeaders();    //the NPE occurs here

To solve the problem,I add some code in your QueueIntFlip.take() method:

        if(!flipped){
            //add this if 
            if(readPos == capacity) {
                readPos = 0;
            }
            if(readPos < writePos){
                return elements[readPos++];
            } else {
                return -1;
            }
        }

I think the variable startIndexOfPartialMessage should be endIndex, not bodyStartIndex + httpHeaders.contentLength or endIndex + 1, since the endIndex does point to the next byte of a http message body end(the implementation can be found in the HttpUtil.parseHttpRequest method),
Additionally, I dont think the code

            if(!flipped){
              //add this if 
              if(readPos == capacity) {
                  readPos = 0;
              }
              if(readPos < writePos){
                  return elements[readPos++];
              } else {
                  return -1;
              }
          }
``` that you mentioned is right, because if you do that, in the case  ` writePos == capacity readPos == capacity flipped == false` which means the all the MessageBuffer blocks are free, then you call the `take()` function again, the `readPos` will be 0, and the writePos and flipped wont be changed, that cause a repeated reading.

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