Copilot commented on code in PR #3019:
URL: https://github.com/apache/pekko/pull/3019#discussion_r3330277290


##########
stream/src/main/scala/org/apache/pekko/stream/impl/io/TlsGraphStage.scala:
##########
@@ -567,15 +563,13 @@ import pekko.util.ByteString
       }
 
       private def growTransportOutBuffer(): Unit = {
-        val oldBuffer = transportOutBuffer
-        val oldCapacity = oldBuffer.capacity()
+        val oldCapacity = transportOutBuffer.capacity()
         if (oldCapacity > Int.MaxValue / 2)
           throw new IllegalStateException(s"Cannot grow TLS transport output 
buffer beyond $oldCapacity bytes")
 
-        val bigger = acquireTransportBuffer(oldCapacity * 2)
+        val bigger = ByteBuffer.allocate(oldCapacity * 2)
         transportOutBuffer.flip()
         bigger.put(transportOutBuffer)
-        releaseTransportBuffer(oldBuffer)
         transportOutBuffer = bigger
       }

Review Comment:
   `growTransportOutBuffer()` is intended (per PR description and 
`canContinueWrapping`) to cap growth at `MaxApplicationRecordsPerEngineCall` 
packets, but the current implementation always doubles the capacity and can 
overshoot `maxTransportOutBufferSize` (e.g. 3*packetSize -> 6*packetSize when 
max is 4*packetSize). This can allocate more heap per connection than intended.
   
   Consider clamping the new capacity to `maxTransportOutBufferSize` and 
failing fast if growth is requested beyond that cap.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to