APEX CNO

APEX Daily Pulse — 2026-11-11

Request EOF Is Not Connection Closure

[✅ Verified] Pillar: Reachback and communications

[❓ Unverified] Duration: 4–6 minutes

Reactivation target: Mark an EOF-delimited request complete without discarding the connection needed for its reply.

Prerequisites

- Python 3.12+ and a Bash-compatible terminal.

- Owned equipment; IPv4 loopback only.

- No elevated privileges or external network access.

Actions

  1. 1. Run this complete fixture. It creates a loopback TCP connection, sends a request, and checks whether the receiver has an end-of-request signal:
python3 - <<'PY'
import socket

def receive_exact(sock: socket.socket, count: int) -> bytes:
 """Read a bounded byte count or reject premature EOF."""
 data = bytearray()
 while len(data) < count:
 block = sock.recv(count - len(data))
 if not block:
 raise EOFError("connection ended before expected bytes")
 data.extend(block)
 return bytes(data)

request = b"probe\n"
reply = b"status=complete\n"

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as listener:
 listener.settimeout(2)
 listener.bind(("127.0.0.1", 0))
 listener.listen(1)

 with socket.create_connection(
 listener.getsockname(), timeout=2
 ) as client:
 server, _ = listener.accept()
 with server:
 server.settimeout(0.25)
 client.sendall(request)
 received = receive_exact(server, len(request))

 # Controlled checkpoint: all request bytes have arrived,
 # but the sender has not marked its write side complete.
 eof_before_shutdown = False
 waiting_for_eof = False
 try:
 eof_before_shutdown = server.recv(1) == b""
 except TimeoutError:
 waiting_for_eof = True

 # End only the client-to-server direction.
 client.shutdown(socket.SHUT_WR)
 eof_after_shutdown = server.recv(1) == b""

 # The reverse direction remains usable.
 server.sendall(reply)
 received_reply = receive_exact(client, len(reply))

passed = (
 received == request
 and waiting_for_eof
 and not eof_before_shutdown
 and eof_after_shutdown
 and received_reply == reply
)

print(f"request_bytes={len(received)}")
print(f"waiting_for_eof={waiting_for_eof}")
print(f"eof_before_shutdown={eof_before_shutdown}")
print(f"eof_after_shutdown={eof_after_shutdown}")
print(f"reply_received={received_reply == reply}")
print(f"drill_passed={passed}")
raise SystemExit(0 if passed else 1)
PY
  1. 2. Compare the observed flags with the expected signal below. Confirm that the reply arrives after the sender has closed its write direction.
  1. 3. Locate the two different operations in the fixture: shutdown(SHUT_WR) ends outgoing data; the context-manager exit later closes the socket. Do not replace the first operation with close() when the protocol requires a reply on that socket.

Observable signal

[❓ Unverified] Expected output; this fixture was not executed in this run:

request_bytes=6
waiting_for_eof=True
eof_before_shutdown=False
eof_after_shutdown=True
reply_received=True
drill_passed=True

[✅ Verified] TCP has independent directions. A write-side shutdown signals EOF after queued outgoing bytes. It does not close the local read direction. A newline has no end-of-request meaning unless the application protocol assigns it that meaning.

Success condition

The receiver first waits for EOF despite having all six request bytes. After the half-close, it detects EOF and sends a reply that the client receives intact. All six assertions pass.

Failure signature

[❌ Speculative] Request bytes are present, but the service waits until timeout and never replies. In an EOF-delimited protocol, a missing write-side shutdown can produce this state. Check the protocol contract before attributing it to service failure.

Python unavailable: Perl alternative

Use Perl's core Socket module. This local socket-pair fixture tests the same directional-closure mechanism without TCP routing:

perl -MSocket=AF_UNIX,SOCK_STREAM,PF_UNSPEC -e '
use strict;
use warnings;

socketpair(my $client, my $server,
 AF_UNIX, SOCK_STREAM, PF_UNSPEC) or die $!;

syswrite($client, "probe") == 5 or die "short request";
shutdown($client, 1) or die "shutdown: $!";

my $request = "";
while (1) {
 my $count = sysread($server, my $part, 1024);
 defined($count) or die "read: $!";
 last if $count == 0;
 $request .= $part;
}

syswrite($server, "OK") == 2 or die "short reply";
shutdown($server, 1) or die "shutdown: $!";

my $reply = "";
while (1) {
 my $count = sysread($client, my $part, 1024);
 defined($count) or die "read: $!";
 last if $count == 0;
 $reply .= $part;
}

print "request=$request\nreply=$reply\n";
exit(($request eq "probe" && $reply eq "OK") ? 0 : 1);
'

[❓ Unverified] Expected alternative output: request=probe and reply=OK.

Boundary check

[✅ Verified] Hidden assumption: the peer uses EOF to delimit requests. Length-prefixed and delimiter-framed protocols can finish a request without half-close. Use their declared framing instead. EOF also does not prove acceptance or execution; retain a separate application acknowledgement.

Adaptation question

Which APEX reachback clients must finish sending before they can receive an acknowledgement—and what signal actually ends their request?