relays: fix runnaway closed connection loop

This commit is contained in:
Emery Hemingway 2024-05-04 00:26:51 +02:00
parent 81792ac4ce
commit 4fb0285190
2 changed files with 17 additions and 11 deletions

View File

@ -324,10 +324,12 @@ when defined(posix):
while entity.alive:
buf[].setLen(0x1000)
let n = read(entity.stdin, buf)
if n == 0:
stopActor(entity.facet)
else:
if n > 0:
entity.relay.recv(buf[], 0..<n)
else:
entity.alive = false
if n < 0: raiseOSError(osLastError())
stopActor(entity.facet)
proc connectTransport(turn: Turn; ds: Cap; ta: transportAddress.Stdio) =
## Connect to an external dataspace over stdio.
@ -405,11 +407,12 @@ when defined(posix):
while entity.alive:
buf[].setLen(0x1000)
let n = read(entity.sock, buf)
if n < 0: raiseOSError(osLastError())
elif n == 0:
stopActor(entity.facet)
else:
if n > 0:
entity.relay.recv(buf[], 0..<n)
else:
entity.alive = false
if n < 0: raiseOSError(osLastError())
stopActor(entity.facet)
# the socket closes when the actor is stopped
proc boot(entity: TcpEntity; ta: transportAddress.Tcp; ds: Cap) {.asyncio.} =
@ -422,8 +425,9 @@ when defined(posix):
template spawnSocketRelay() {.dirty.} =
proc writeConn(turn: Turn; buf: seq[byte]) =
discard trampoline:
whelp write(entity.sock, buf)
if entity.alive:
discard trampoline:
whelp write(entity.sock, buf)
var ops = RelayActorOptions(
packetWriter: writeConn,
initialOid: 0.Oid.some,
@ -548,7 +552,9 @@ proc connectRoute(turn: Turn; ds: Cap; route: Route; transOff: int) =
2: ?:ResolvedAccepted,
}
onPublish(turn, ds, acceptPat) do (origin: Cap):
walk(turn, ds, origin, route, transOff, 0)
origin.relay.run do (turn: Turn):
# walk using the facet that manages the transport connection
walk(turn, ds, origin, route, transOff, 0)
type StepCallback = proc (turn: Turn; step: Value; origin: Cap; res: Resolved) {.closure.}

View File

@ -1,6 +1,6 @@
# Package
version = "20240430"
version = "20240504"
author = "Emery Hemingway"
description = "Syndicated actors for conversational concurrency"
license = "Unlicense"