You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2020/06/10 02:20:26 UTC

[GitHub] [servicecomb-java-chassis] jungan21 commented on a change in pull request #1825: [SCB-1995]Fix incorrect message issue identifed through testing

jungan21 commented on a change in pull request #1825:
URL: https://github.com/apache/servicecomb-java-chassis/pull/1825#discussion_r437822660



##########
File path: service-registry/registry-zero-config/src/main/java/org/apache/servicecomb/zeroconfig/server/ServerUtil.java
##########
@@ -179,12 +179,12 @@ private static ServerMicroserviceInstance buildServerMicroserviceInstanceFromMap
 
   private static void startListenerForRegisterUnregisterEvent() {
     try {
-      byte[] buffer = new byte[DATA_PACKET_BUFFER_SIZE];
       multicastSocket = new MulticastSocket(PORT);
       group = InetAddress.getByName(GROUP);
       multicastSocket.joinGroup(group); // need to join the group to be able to receive the data
 
       while (true) {
+        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);

Review comment:
       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
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org