He-Pin opened a new issue, #3255:
URL: https://github.com/apache/pekko/issues/3255

   ### Motivation
   
   `TcpConnectionStage.closeConnectionUpstreamFinished()` has a null-safety gap 
when `halfClose=false`. The null check at line 406 only protects the 
`halfClose=true` path, leaving `connection ! Close` unprotected in the 
`halfClose=false` path.
   
   ### Current Behavior
   
   
`stream/src/main/scala/org/apache/pekko/stream/impl/io/TcpStages.scala:398-416`:
   
   ```scala
   private def closeConnectionUpstreamFinished(): Unit = {
     if (isClosed(bytesOut) || !role.halfClose) {
       // When halfClose=false, ALWAYS enters here
       if (writeInProgress)
         connectionClosePending = true
       else
         connection ! Close  // ⚠️ NO null check — NPE if connection is null
     } else if (connection ne null) {  // ✅ null check only for halfClose=true 
path
       ...
     }
   }
   ```
   
   `connection` starts as `null` (line 267: `private var connection: ActorRef = 
_`) and is only set when the `Connected` message arrives. The developers 
acknowledge upstream signals can arrive before connection — `onUpstreamFailure` 
at line 484 has an explicit null check (`if (connection ne null)`), but 
`closeConnectionUpstreamFinished` does not.
   
   ### Secondary Issue
   
   In the `connecting` handler (line 325), when `isClosed(bytesIn)`, it sends 
`ConfirmedClose` (half-close) instead of `Close` (full close) regardless of 
`halfClose` setting. This is semantically wrong when `halfClose=false`.
   
   ### Expected Behavior
   
   Add null check in `closeConnectionUpstreamFinished()` first branch, and send 
`Close` (not `ConfirmedClose`) when `halfClose=false` in the `connecting` 
handler.
   
   ### Environment
   
   - Pekko Stream (any version)
   - `TcpStages.scala:398-416`, `TcpStages.scala:325`
   
   ### References
   
   None


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