pjfanning opened a new pull request, #1880:
URL: https://github.com/apache/pekko-connectors/pull/1880

   ### Motivation
   `UnixDomainSocketSpec`'s "send and receive more ten times the size of a 
buffer" test (disabled since 2019) stalls part way through the transfer: the 
echoing server never writes a byte, its receive queue then fills, backpressure 
disables its reads, and both directions deadlock.
   
   The root cause is in jnr-enxio's `KQSelector` (macOS/BSD): it registers 
kqueue filters edge-triggered (`EV_ADD|EV_ENABLE|EV_CLEAR`), and its `poll()` 
**overwrites** a key's `readyOps` for each returned kevent entry instead of 
OR-ing them. When `EVFILT_READ` and `EVFILT_WRITE` for the same channel arrive 
in one batch, the entry processed last clobbers the other's readiness — and 
since the filter is edge-triggered, the consumed edge never fires again. The 
connector's NIO event loop gated writes on `key.isWritable` and reads on 
`key.isReadable`, so a clobbered event stalled that direction forever. Debug 
logs of the stalled test show the server's key repeatedly selected 
`readable=true, writable=false` with a pending `SendRequested` and `OP_WRITE` 
registered, while its socket was empty and trivially writable.
   
   ### Modification
   In `UnixDomainSocketImpl.nioEventLoop`, attempt a pending write or read 
whenever the key is selected, rather than only when the (unreliable) ready ops 
report readiness. A non-blocking operation on a not-ready socket returns 0, 
which is now handled: an unfinished write keeps `OP_WRITE` registered, and a 
0-byte read is a no-op instead of being mistaken for EOF. This is self-healing 
by construction: a readiness edge can only be lost to another event on the same 
key arriving in the same batch, and that event now triggers the retry.
   
   Re-enable the throughput test.
   
   ### Result
   Sustained transfers complete. The re-enabled test passes in ~250ms instead 
of timing out after a minute, and the rest of the spec is unaffected. Linux was 
likely unaffected (jnr-enxio uses the level-triggered poll(2) selector there), 
so CI exercising this test on Linux should be safe; the fix removes the 
macOS/BSD stall.
   
   ### Tests
   - `sbt "unix-domain-socket/testOnly docs.scaladsl.UnixDomainSocketSpec"` — 
all 7 tests pass, stable over 5 consecutive runs (macOS). The re-enabled test 
reproduced the stall before the fix and is the directional regression test.
   
   ### References
   Fixes #1858


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