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

[SCB-1995]Fix incorrect message issue identifed through testing #1825

Merged
merged 1 commit into from
Jun 10, 2020
Merged

[SCB-1995]Fix incorrect message issue identifed through testing #1825

merged 1 commit into from
Jun 10, 2020

Conversation

jungan21
Copy link
Contributor

@jungan21 jungan21 commented Jun 9, 2020

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Make sure there is a JIRA issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a JIRA issue. Your pull request should address just this issue, without pulling in other changes.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Format the pull request title like [SCB-XXX] Fixes bug in ApproximateQuantiles, where you replace SCB-XXX with the appropriate JIRA issue.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Run mvn clean install -Pit to make sure basic checks pass. A more thorough check will be performed on your pull request automatically.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

@coveralls
Copy link

coveralls commented Jun 9, 2020

Coverage Status

Coverage increased (+0.4%) to 86.816% when pulling c497ee1 on jungan21:master into 1c4f7c6 on apache:master.

Comment on lines 187 to 190
byte[] buffer = new byte[DATA_PACKET_BUFFER_SIZE];
DatagramPacket receivePacketBuffer = new DatagramPacket(buffer, buffer.length);
multicastSocket.receive(receivePacketBuffer);
String receivedPacketString = new String(receivePacketBuffer.getData(), ENCODE);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic seams not correct. Maybe you'd check the length of data actually received and using the correct data.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point. Unfortunately, based on the Multicast working mechanism, we have to create a buffer before data is received. After data is received, then buffer is filled with the received data. So we can't create a buffer with size exactly same as the received data.

By the way, it's also mentioned in the JDK source code comments:
https://github.com/frohoff/jdk8u-jdk/blob/master/src/share/classes/java/net/DatagramSocket.java#L698-L700

Copy link
Contributor

@liubao68 liubao68 Jun 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you misunderstanding my point. You should do this

 multicastSocket.receive(receivePacketBuffer);
int len = receivePacketBuffer.getLength() ;
if(len > 0) {
   String receivedPacketString = new String(receivePacketBuffer.getData(), 0, len, ENCODE);
}

And you can avoid creating new buffers for each receive, though this is not very important because the next receive happens in seconds.

@liubao68 liubao68 merged commit 0aee752 into apache:master Jun 10, 2020
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

Successfully merging this pull request may close these issues.

None yet

3 participants