Github user mosermw commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1637#discussion_r109018746
  
    --- Diff: 
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/protocol/impl/SocketProtocolListener.java
 ---
    @@ -134,15 +132,21 @@ public void dispatchRequest(final Socket socket) {
     
                 // unmarshall message
                 final ProtocolMessageUnmarshaller<ProtocolMessage> 
unmarshaller = protocolContext.createUnmarshaller();
    -            final InputStream inStream = socket.getInputStream();
    -            final CopyingInputStream copyingInputStream = new 
CopyingInputStream(inStream, maxMsgBuffer); // don't copy more than 1 MB
    +            final ByteCountingInputStream countingIn = new 
ByteCountingInputStream(socket.getInputStream());
    +            InputStream wrappedInStream = countingIn;
    +            if (logger.isDebugEnabled()) {
    +                final int maxMsgBuffer = 1024 * 1024;   // don't buffer 
more than 1 MB of the message
    +                final CopyingInputStream copyingInputStream = new 
CopyingInputStream(wrappedInStream, maxMsgBuffer);
    +                wrappedInStream = copyingInputStream;
    +            }
     
                 final ProtocolMessage request;
                 try {
    -                request = unmarshaller.unmarshal(copyingInputStream);
    +                request = unmarshaller.unmarshal(wrappedInStream);
                 } finally {
    -                receivedMessage = copyingInputStream.getBytesRead();
                     if (logger.isDebugEnabled()) {
    --- End diff --
    
    Excellent!  I thought of using instanceof CopyingInputStream but didn't 
think it would help.  The potential race condition makes it useful and 
necessary.  I pushed a fix, will squash if needed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to