@graftland/plugin-remote 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Auth.d.ts +2 -2
- package/dist/Auth.d.ts.map +1 -1
- package/dist/Auth.js.map +1 -1
- package/dist/{Bootstrap-MCwivGN1.js → Bootstrap-H9gDsgsC.js} +2 -2
- package/dist/{Contract-CcpSIJm4.js → Contract-DsJtisvL.js} +8 -46
- package/dist/Contract.d.ts +50 -53
- package/dist/Contract.d.ts.map +1 -1
- package/dist/Contract.js +1 -1
- package/dist/Contract.js.map +1 -1
- package/dist/{Errors-oPsTLY7l.js → Errors-DYhsGZcZ.js} +14 -1
- package/dist/Errors.d.ts +19 -0
- package/dist/Errors.d.ts.map +1 -1
- package/dist/Errors.js +14 -1
- package/dist/Errors.js.map +1 -1
- package/dist/{FailureGroup-BcH0XOBi.js → FailureGroup-BgT73AaR.js} +14 -4
- package/dist/{Framing-zaYdOJnT.js → Framing-G9eSaeLb.js} +1 -1
- package/dist/{Graft-BsYq3F-J.js → Graft-B71CPA2Y.js} +46 -35
- package/dist/{Packages-B1TPk8pa.js → Packages-AgoCGotL.js} +23 -26
- package/dist/{Peer-IJgFK6mD.js → Peer-DXeVrGBh.js} +5 -5
- package/dist/{ProcessObservation-DEGrEMfP.js → ProcessObservation-gLgGirYv.js} +1 -1
- package/dist/{ServeLifecycle-CJM0gG5B.js → ServeLifecycle-Bd1FPJ6e.js} +1 -1
- package/dist/Testing.d.ts +4 -4
- package/dist/Testing.d.ts.map +1 -1
- package/dist/Testing.js +10 -4
- package/dist/Testing.js.map +1 -1
- package/dist/Transport.d.ts +2 -2
- package/dist/Transport.d.ts.map +1 -1
- package/dist/Transport.js.map +1 -1
- package/dist/bin.js +48 -47
- package/dist/bin.js.map +1 -1
- package/dist/{childRuntime-DSqtFN9o.js → childRuntime-Bm3iSg_N.js} +30 -26
- package/dist/connectionEnded-BwcxQ7W8.js +54 -0
- package/dist/{entry-SYsx9VNb.js → entry-psOpX3Bj.js} +76 -48
- package/dist/host/auth/bearer.d.ts +1 -2
- package/dist/host/auth/bearer.d.ts.map +1 -1
- package/dist/host/auth/bearer.js +1 -1
- package/dist/host/auth/bearer.js.map +1 -1
- package/dist/host/auth/jwt.d.ts +1 -2
- package/dist/host/auth/jwt.d.ts.map +1 -1
- package/dist/host/auth/jwt.js +1 -1
- package/dist/host/auth/jwt.js.map +1 -1
- package/dist/host/auth/mtls.js +2 -2
- package/dist/host/auth/none.js +1 -1
- package/dist/host/command.d.ts +1 -1
- package/dist/host/command.d.ts.map +1 -1
- package/dist/host/command.js +4 -4
- package/dist/host/command.js.map +1 -1
- package/dist/host/local.d.ts +1 -2
- package/dist/host/local.d.ts.map +1 -1
- package/dist/host/local.js +3 -3
- package/dist/host/local.js.map +1 -1
- package/dist/host/unix.d.ts +1 -1
- package/dist/host/unix.d.ts.map +1 -1
- package/dist/host/unix.js +3 -3
- package/dist/host/unix.js.map +1 -1
- package/dist/host/websocket.d.ts +1 -1
- package/dist/host/websocket.d.ts.map +1 -1
- package/dist/host/websocket.js +3 -3
- package/dist/host/websocket.js.map +1 -1
- package/dist/host/worker.d.ts +1 -2
- package/dist/host/worker.d.ts.map +1 -1
- package/dist/host/worker.js +4 -5
- package/dist/host/worker.js.map +1 -1
- package/dist/{importer-D7zSgqxq.js → importer-Cvf88eAY.js} +5 -8
- package/dist/index.d.ts +2 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -10
- package/dist/index.js.map +1 -1
- package/dist/internal/Certificates.js +4 -4
- package/dist/internal/Certificates.js.map +1 -1
- package/dist/internal/FailureGroup.js +3 -2
- package/dist/internal/FailureGroup.js.map +1 -1
- package/dist/internal/assembly.js +9 -2
- package/dist/internal/assembly.js.map +1 -1
- package/dist/internal/auth/mtls.js +1 -1
- package/dist/internal/auth/mtls.js.map +1 -1
- package/dist/internal/auth/tokenCredentials.d.ts +0 -1
- package/dist/internal/auth/tokenCredentials.d.ts.map +1 -1
- package/dist/internal/auth/tokenCredentials.js.map +1 -1
- package/dist/internal/child.js +20 -17
- package/dist/internal/child.js.map +1 -1
- package/dist/internal/childRuntime.js +6 -4
- package/dist/internal/childRuntime.js.map +1 -1
- package/dist/internal/contract.js +26 -0
- package/dist/internal/contract.js.map +1 -0
- package/dist/internal/credentials.d.ts +6 -6
- package/dist/internal/credentials.d.ts.map +1 -1
- package/dist/internal/credentials.js.map +1 -1
- package/dist/internal/directTransport.d.ts +1 -1
- package/dist/internal/entry.d.ts +1 -2
- package/dist/internal/entry.d.ts.map +1 -1
- package/dist/internal/entry.js +4 -14
- package/dist/internal/entry.js.map +1 -1
- package/dist/internal/execution.js +44 -7
- package/dist/internal/execution.js.map +1 -1
- package/dist/internal/host/runner.js +7 -6
- package/dist/internal/host/runner.js.map +1 -1
- package/dist/internal/host.js +5 -5
- package/dist/internal/host.js.map +1 -1
- package/dist/internal/port.d.ts +2 -10
- package/dist/internal/port.js +5 -5
- package/dist/internal/port.js.map +1 -1
- package/dist/internal/release.js +1 -1
- package/dist/internal/release.js.map +1 -1
- package/dist/internal/runner/Connection.d.ts +1 -1
- package/dist/internal/runner/Connection.js +4 -4
- package/dist/internal/runner/Connection.js.map +1 -1
- package/dist/internal/runner/Execution.js +3 -3
- package/dist/internal/runner/Execution.js.map +1 -1
- package/dist/internal/runner/Framing.d.ts +1 -11
- package/dist/internal/runner/Framing.js +1 -1
- package/dist/internal/runner/Framing.js.map +1 -1
- package/dist/internal/runner/Local.js +1 -1
- package/dist/internal/runner/Local.js.map +1 -1
- package/dist/internal/runner/Lock.js +1 -1
- package/dist/internal/runner/Lock.js.map +1 -1
- package/dist/internal/runner/Packages.d.ts +1 -1
- package/dist/internal/runner/Packages.js +22 -25
- package/dist/internal/runner/Packages.js.map +1 -1
- package/dist/internal/runner/Processes.js +7 -9
- package/dist/internal/runner/Processes.js.map +1 -1
- package/dist/internal/runner/Store.js +3 -3
- package/dist/internal/runner/Store.js.map +1 -1
- package/dist/internal/runner/Supervisor.js +46 -47
- package/dist/internal/runner/Supervisor.js.map +1 -1
- package/dist/internal/runner/accept.js +3 -3
- package/dist/internal/runner/accept.js.map +1 -1
- package/dist/internal/runner/model.js +1 -1
- package/dist/internal/runner/model.js.map +1 -1
- package/dist/internal/serve.js +1 -1
- package/dist/internal/serve.js.map +1 -1
- package/dist/internal/services.d.ts +2 -12
- package/dist/internal/services.d.ts.map +1 -1
- package/dist/internal/services.js.map +1 -1
- package/dist/internal/supervisorPlugin.js +1 -1
- package/dist/internal/watchdogMain.js +5 -5
- package/dist/internal/watchdogMain.js.map +1 -1
- package/dist/internal/websocketServer.js +3 -1
- package/dist/internal/websocketServer.js.map +1 -1
- package/dist/internal/workerMain.js +3 -3
- package/dist/{port-Blbh8tms.js → port--3x2zJ4D.js} +8 -8
- package/dist/{release-BY4Mlluy.js → release-DfZPuIcK.js} +1 -1
- package/dist/runner/auth/bearer.js +2 -2
- package/dist/runner/auth/jwt.js +4 -4
- package/dist/runner/auth/jwt.js.map +1 -1
- package/dist/runner/auth/mtls.js +3 -3
- package/dist/runner/auth/none.js +1 -1
- package/dist/runner/index.js +5 -5
- package/dist/runner/stdio.js +3 -3
- package/dist/runner/unix.js +3 -3
- package/dist/runner/websocket.js +4 -4
- package/dist/{socketChannel-KmtzF-9G.js → socketChannel-CJvL2DiB.js} +2 -2
- package/dist/{supervisorPlugin-Inb1S5IV.js → supervisorPlugin-t6Z6PrhD.js} +72 -76
- package/dist/{token-v5ne2I0-.js → token-CYBNNlhS.js} +1 -1
- package/dist/{tokenCredentials-WUJm2AKm.js → tokenCredentials-CbCuk-Rt.js} +3 -3
- package/dist/{websocketServer-MXcCJx0v.js → websocketServer-NQhODlEt.js} +5 -3
- package/dist/{workerChannel-P82YdNjh.js → workerChannel-C8hhBJzA.js} +1 -1
- package/package.json +3 -3
- package/src/Auth.ts +9 -2
- package/src/Contract.ts +67 -51
- package/src/Errors.ts +23 -0
- package/src/Testing.ts +16 -2
- package/src/Transport.ts +6 -2
- package/src/bin.ts +28 -30
- package/src/host/auth/bearer.ts +1 -6
- package/src/host/auth/jwt.ts +1 -6
- package/src/host/command.ts +2 -0
- package/src/host/local.ts +5 -9
- package/src/host/unix.ts +2 -0
- package/src/host/websocket.ts +2 -0
- package/src/host/worker.ts +4 -6
- package/src/index.ts +8 -4
- package/src/internal/Certificates.ts +10 -13
- package/src/internal/FailureGroup.ts +128 -121
- package/src/internal/assembly.ts +19 -10
- package/src/internal/auth/mtls.ts +19 -20
- package/src/internal/auth/tokenCredentials.ts +1 -7
- package/src/internal/child.ts +249 -240
- package/src/internal/childRuntime.ts +84 -81
- package/src/internal/contract.ts +47 -0
- package/src/internal/credentials.ts +12 -9
- package/src/internal/entry.ts +11 -25
- package/src/internal/execution.ts +73 -14
- package/src/internal/host/runner.ts +153 -153
- package/src/internal/host.ts +123 -130
- package/src/internal/port.ts +100 -103
- package/src/internal/release.ts +3 -2
- package/src/internal/runner/Connection.ts +52 -60
- package/src/internal/runner/Execution.ts +163 -164
- package/src/internal/runner/Framing.ts +9 -10
- package/src/internal/runner/Local.ts +26 -27
- package/src/internal/runner/Lock.ts +23 -25
- package/src/internal/runner/Packages.ts +67 -70
- package/src/internal/runner/Processes.ts +89 -92
- package/src/internal/runner/Store.ts +110 -114
- package/src/internal/runner/Supervisor.ts +392 -405
- package/src/internal/runner/accept.ts +76 -84
- package/src/internal/runner/model.ts +20 -21
- package/src/internal/serve.ts +15 -13
- package/src/internal/services.ts +1 -19
- package/src/internal/watchdogMain.ts +16 -11
- package/src/internal/websocketServer.ts +18 -3
- package/src/runner/auth/jwt.ts +10 -6
- package/dist/cleanup-BPWr-5U9.js +0 -13
- package/dist/connectionEnded-DUgcobEd.js +0 -9
- package/dist/internal/childErrors.d.ts +0 -33
- package/dist/internal/childErrors.d.ts.map +0 -1
- package/dist/internal/port.d.ts.map +0 -1
- package/dist/internal/runner/Framing.d.ts.map +0 -1
|
@@ -19,169 +19,169 @@ import * as Multiplex from "../runner/Multiplex"
|
|
|
19
19
|
import * as Packages from "../runner/Packages"
|
|
20
20
|
import * as Wire from "../runner/Wire"
|
|
21
21
|
import { awaitTermination, defaults, childOf } from "../runner/model"
|
|
22
|
-
export const connect = (
|
|
22
|
+
export const connect = Effect.fnUntraced(function* (
|
|
23
23
|
target: ConfiguredRunner,
|
|
24
24
|
contractModule: string,
|
|
25
25
|
options: Port.Options,
|
|
26
26
|
resources: Scope.Scope,
|
|
27
27
|
processScope: Scope.Scope,
|
|
28
|
-
)
|
|
29
|
-
|
|
30
|
-
const instance = target.instance
|
|
28
|
+
) {
|
|
29
|
+
const instance = target.instance
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
31
|
+
const margin = Duration.toMillis(target.margin ?? "5 seconds")
|
|
32
|
+
const channel = yield* connectCapability(target.explicitAuth).pipe(
|
|
33
|
+
Scope.provide(processScope),
|
|
34
|
+
)
|
|
35
|
+
const mux = yield* Multiplex.make(channel).pipe(Scope.provide(resources))
|
|
36
|
+
const control = yield* Port.make(Wire.channel(mux, 0), {
|
|
37
|
+
session: "session-v1",
|
|
38
|
+
serve: {},
|
|
39
|
+
call: { session: Wire.Session },
|
|
40
|
+
}).pipe(Scope.provide(resources))
|
|
41
|
+
const session = yield* RpcClient.make(Wire.Session).pipe(
|
|
42
|
+
Effect.provideService(
|
|
43
|
+
RpcClient.Protocol,
|
|
44
|
+
control.clientProtocol("session"),
|
|
45
|
+
),
|
|
46
|
+
Scope.provide(resources),
|
|
47
|
+
)
|
|
48
|
+
const expectedGeneration = yield* session.HighWater({ instance })
|
|
49
|
+
const record = yield* session.Open({
|
|
50
|
+
instance,
|
|
51
|
+
expectedGeneration,
|
|
52
|
+
requestId: options.session,
|
|
53
|
+
limits: defaults,
|
|
54
|
+
...(target.lease === undefined
|
|
55
|
+
? {}
|
|
56
|
+
: {
|
|
57
|
+
leaseMillis: Duration.toMillis(target.lease),
|
|
58
|
+
}),
|
|
59
|
+
})
|
|
60
|
+
const failures = yield* FailureGroup.make<TransportError>().pipe(
|
|
61
|
+
Scope.provide(resources),
|
|
62
|
+
)
|
|
63
|
+
const finishStarted = yield* Ref.make(false)
|
|
64
|
+
const terminate = yield* Effect.cached(
|
|
65
|
+
Effect.gen(function* () {
|
|
66
|
+
yield* Ref.set(finishStarted, true)
|
|
67
|
+
// A failed close must not skip Dispose; both outcomes are reported together below.
|
|
68
|
+
const closed = yield* Effect.exit(failures.close)
|
|
69
|
+
const result = yield* awaitTermination(
|
|
70
|
+
record.handle,
|
|
71
|
+
session.Dispose(record.handle),
|
|
72
|
+
record.leaseMillis,
|
|
73
|
+
margin,
|
|
74
|
+
)
|
|
75
|
+
const { code, signal, stderr, cause } = result.exit
|
|
76
|
+
yield* Effect.logInfo("Remote execution terminated", {
|
|
77
|
+
code,
|
|
78
|
+
...(signal === null ? {} : { signal }),
|
|
79
|
+
...(stderr === undefined || stderr === "" ? {} : { stderr }),
|
|
80
|
+
...(cause === undefined || cause.reasons.length === 0 ? {} : { cause }),
|
|
81
|
+
}).pipe(
|
|
82
|
+
Effect.annotateLogs({
|
|
83
|
+
"remote.instance": record.handle.key.instance,
|
|
84
|
+
"remote.generation": record.handle.generation,
|
|
85
|
+
"remote.termination": result.kind,
|
|
86
|
+
}),
|
|
87
|
+
)
|
|
88
|
+
const failure = Exit.isFailure(closed)
|
|
89
|
+
? Cause.combine(closed.cause, result.cause)
|
|
90
|
+
: result.cause
|
|
91
|
+
if (failure.reasons.length > 0)
|
|
92
|
+
return yield* Effect.failCause(cleanupCause(failure))
|
|
93
|
+
}),
|
|
94
|
+
)
|
|
95
|
+
yield* Scope.addFinalizer(
|
|
96
|
+
processScope,
|
|
97
|
+
Effect.gen(function* () {
|
|
98
|
+
if (!(yield* Ref.get(finishStarted)))
|
|
99
|
+
yield* terminate.pipe(
|
|
100
|
+
Effect.catchCause((cause) => Effect.failCause(cleanupCause(cause))),
|
|
74
101
|
)
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
102
|
+
}),
|
|
103
|
+
)
|
|
104
|
+
const renewed = yield* Effect.forever(
|
|
105
|
+
Effect.sleep(record.leaseMillis / 3).pipe(
|
|
106
|
+
Effect.andThen(session.Renew(record.handle)),
|
|
107
|
+
),
|
|
108
|
+
).pipe(Effect.forkIn(resources))
|
|
109
|
+
const code = yield* session.Load({
|
|
110
|
+
handle: record.handle,
|
|
111
|
+
specifier: contractModule,
|
|
112
|
+
digest: target.expect?.digest !== undefined,
|
|
113
|
+
})
|
|
114
|
+
yield* Packages.verify(code, target.expect)
|
|
115
|
+
const loaded = yield* session.Status(record.handle)
|
|
116
|
+
const peer = yield* Port.make(Wire.channel(mux, 1), {
|
|
117
|
+
...options,
|
|
118
|
+
session: record.handle.token,
|
|
119
|
+
limits: record.limits,
|
|
120
|
+
}).pipe(Scope.provide(resources))
|
|
121
|
+
// RPC forwarding cancellation is expected; resource cleanup is collected by Connection's scopes.
|
|
122
|
+
const report = (cause: Cause.Cause<unknown>) =>
|
|
123
|
+
Cause.hasInterruptsOnly(cause)
|
|
124
|
+
? Effect.void
|
|
125
|
+
: failures.failCause(
|
|
126
|
+
Cause.map(cause, (error) =>
|
|
127
|
+
TransportError.make({ cause: Cause.fail(error) }),
|
|
128
|
+
),
|
|
89
129
|
)
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}),
|
|
93
|
-
)
|
|
94
|
-
yield* Scope.addFinalizer(
|
|
95
|
-
processScope,
|
|
96
|
-
Effect.gen(function* () {
|
|
97
|
-
if (!(yield* Ref.get(finishStarted)))
|
|
98
|
-
yield* terminate.pipe(
|
|
99
|
-
Effect.catchCause((cause) => Effect.failCause(cleanupCause(cause))),
|
|
100
|
-
)
|
|
101
|
-
}),
|
|
102
|
-
)
|
|
103
|
-
const renewed = yield* Effect.forever(
|
|
104
|
-
Effect.sleep(record.leaseMillis / 3).pipe(
|
|
105
|
-
Effect.andThen(session.Renew(record.handle)),
|
|
106
|
-
),
|
|
107
|
-
).pipe(Effect.forkIn(resources))
|
|
108
|
-
const code = yield* session.Load({
|
|
109
|
-
handle: record.handle,
|
|
110
|
-
specifier: contractModule,
|
|
111
|
-
digest: target.expect?.digest !== undefined,
|
|
112
|
-
})
|
|
113
|
-
yield* Packages.verify(code, target.expect)
|
|
114
|
-
const loaded = yield* session.Status(record.handle)
|
|
115
|
-
const peer = yield* Port.make(Wire.channel(mux, 1), {
|
|
116
|
-
...options,
|
|
117
|
-
session: record.handle.token,
|
|
118
|
-
limits: record.limits,
|
|
119
|
-
}).pipe(Scope.provide(resources))
|
|
120
|
-
// RPC forwarding cancellation is expected; resource cleanup is collected by Connection's scopes.
|
|
121
|
-
const report = (cause: Cause.Cause<unknown>) =>
|
|
130
|
+
yield* failures.await.pipe(
|
|
131
|
+
Effect.catchCause((cause) =>
|
|
122
132
|
Cause.hasInterruptsOnly(cause)
|
|
123
133
|
? Effect.void
|
|
124
|
-
:
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
)
|
|
129
|
-
yield* failures.await.pipe(
|
|
130
|
-
Effect.catchCause((cause) =>
|
|
131
|
-
Cause.hasInterruptsOnly(cause)
|
|
132
|
-
? Effect.void
|
|
133
|
-
: peer.fail(TransportError.make({ cause })),
|
|
134
|
-
),
|
|
135
|
-
Effect.forkIn(resources),
|
|
136
|
-
)
|
|
134
|
+
: peer.fail(TransportError.make({ cause })),
|
|
135
|
+
),
|
|
136
|
+
Effect.forkIn(resources),
|
|
137
|
+
)
|
|
137
138
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
),
|
|
139
|
+
yield* failures.run(
|
|
140
|
+
Fiber.join(renewed).pipe(
|
|
141
|
+
Effect.catchCause(
|
|
142
|
+
Effect.fnUntraced(function* (cause) {
|
|
143
|
+
if (Cause.hasInterruptsOnly(cause)) return
|
|
144
|
+
const status = yield* Effect.exit(
|
|
145
|
+
session.Status(record.handle).pipe(Effect.timeout("5 seconds")),
|
|
146
|
+
)
|
|
147
|
+
if (Exit.isSuccess(status) && status.value.phase === "Stopped") {
|
|
148
|
+
const exit = status.value.termination.exit
|
|
149
|
+
yield* report(
|
|
150
|
+
Cause.combine(
|
|
151
|
+
cause,
|
|
152
|
+
Cause.fail(
|
|
153
|
+
ProcessExited.make({
|
|
154
|
+
pid: Option.map(childOf(loaded), (child) => child.pid),
|
|
155
|
+
exitCode: exit.code,
|
|
156
|
+
stderr: exit.stderr ?? "",
|
|
157
|
+
statusCause: exit.cause ?? Cause.empty,
|
|
158
|
+
}),
|
|
159
159
|
),
|
|
160
|
-
)
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
),
|
|
169
|
-
),
|
|
170
|
-
)
|
|
171
|
-
return {
|
|
172
|
-
resources,
|
|
173
|
-
pid: Option.map(childOf(loaded), (child) => child.pid),
|
|
174
|
-
diagnostics: failures.cause,
|
|
175
|
-
terminate: () =>
|
|
176
|
-
Effect.gen(function* () {
|
|
177
|
-
// No renewal may extend a disconnected session while termination waits out its lease.
|
|
178
|
-
yield* Fiber.interrupt(renewed)
|
|
179
|
-
yield* terminate
|
|
160
|
+
),
|
|
161
|
+
)
|
|
162
|
+
} else
|
|
163
|
+
yield* report(
|
|
164
|
+
Exit.isFailure(status)
|
|
165
|
+
? Cause.combine(cause, status.cause)
|
|
166
|
+
: cause,
|
|
167
|
+
)
|
|
180
168
|
}),
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
169
|
+
),
|
|
170
|
+
),
|
|
171
|
+
)
|
|
172
|
+
return {
|
|
173
|
+
resources,
|
|
174
|
+
pid: Option.map(childOf(loaded), (child) => child.pid),
|
|
175
|
+
diagnostics: failures.cause,
|
|
176
|
+
terminate: Effect.fnUntraced(function* () {
|
|
177
|
+
// No renewal may extend a disconnected session while termination waits out its lease.
|
|
178
|
+
yield* Fiber.interrupt(renewed)
|
|
179
|
+
yield* terminate
|
|
180
|
+
}),
|
|
181
|
+
transport: {
|
|
182
|
+
...peer,
|
|
183
|
+
failure: peer.await,
|
|
184
|
+
report,
|
|
185
|
+
},
|
|
186
|
+
} satisfies Connected
|
|
187
|
+
})
|
package/src/internal/host.ts
CHANGED
|
@@ -16,15 +16,16 @@ import { RemoteWithdrawn } from "../Errors"
|
|
|
16
16
|
import * as Control from "./control"
|
|
17
17
|
import { cleanupCause } from "./cleanup"
|
|
18
18
|
import { Connection } from "./runner/Connection"
|
|
19
|
-
import type { Service } from "
|
|
19
|
+
import type { Service } from "../Contract"
|
|
20
|
+
import type { ChildFailure } from "./childErrors"
|
|
21
|
+
import type { prepare } from "./contract"
|
|
20
22
|
|
|
21
23
|
type ErrorSchema = Schema.Top & {
|
|
22
24
|
readonly DecodingServices: never
|
|
23
25
|
readonly EncodingServices: never
|
|
24
26
|
}
|
|
25
|
-
type ControlGroup<E extends ErrorSchema> =
|
|
26
|
-
Schema.Codec<unknown, Schema.Json>,
|
|
27
|
-
E
|
|
27
|
+
type ControlGroup<E extends ErrorSchema> = ReturnType<
|
|
28
|
+
typeof prepare<Schema.Codec<unknown, Schema.Json>, E>
|
|
28
29
|
>["control"]
|
|
29
30
|
interface Contract<E extends ErrorSchema> {
|
|
30
31
|
readonly control: ControlGroup<E>
|
|
@@ -32,9 +33,7 @@ interface Contract<E extends ErrorSchema> {
|
|
|
32
33
|
readonly decodeCause: (
|
|
33
34
|
input: unknown,
|
|
34
35
|
) => Effect.Effect<
|
|
35
|
-
Cause.Cause<
|
|
36
|
-
E["Type"] | ContractModule.UndeclaredFailure | ContractModule.ChildFailure
|
|
37
|
-
>,
|
|
36
|
+
Cause.Cause<E["Type"] | ContractModule.UndeclaredFailure | ChildFailure>,
|
|
38
37
|
Schema.SchemaError
|
|
39
38
|
>
|
|
40
39
|
}
|
|
@@ -47,121 +46,118 @@ const race = <A, E, R>(
|
|
|
47
46
|
effect: Effect.Effect<A, E, R>,
|
|
48
47
|
) => Effect.raceFirst(effect, connection.transport.failure)
|
|
49
48
|
|
|
50
|
-
const forwardEvents = <E extends ErrorSchema>(
|
|
49
|
+
const forwardEvents = Effect.fnUntraced(function* <E extends ErrorSchema>(
|
|
51
50
|
contract: Contract<E>,
|
|
52
51
|
client: Client<E>,
|
|
53
52
|
connection: Connection["Service"],
|
|
54
|
-
)
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const forwardLogs = <E extends ErrorSchema>(
|
|
53
|
+
) {
|
|
54
|
+
const stopped = yield* Deferred.make<void>()
|
|
55
|
+
const remoteFailure = yield* FailureGroup.make<
|
|
56
|
+
| E["Type"]
|
|
57
|
+
| ContractModule.UndeclaredFailure
|
|
58
|
+
| ChildFailure
|
|
59
|
+
| RemoteWithdrawn
|
|
60
|
+
>()
|
|
61
|
+
const events = yield* race(
|
|
62
|
+
connection,
|
|
63
|
+
client.Events().pipe(
|
|
64
|
+
Stream.runForEach((event) => {
|
|
65
|
+
switch (event._tag) {
|
|
66
|
+
case "Stopped":
|
|
67
|
+
return Deferred.succeed(stopped, undefined)
|
|
68
|
+
case "Withdrawing":
|
|
69
|
+
return remoteFailure.fail(RemoteWithdrawn.make({}))
|
|
70
|
+
case "Failed":
|
|
71
|
+
return contract
|
|
72
|
+
.decodeCause(event.cause)
|
|
73
|
+
.pipe(Effect.flatMap((cause) => remoteFailure.failCause(cause)))
|
|
74
|
+
}
|
|
75
|
+
}),
|
|
76
|
+
),
|
|
77
|
+
).pipe(
|
|
78
|
+
Effect.tapCause(connection.transport.report),
|
|
79
|
+
Effect.forkIn(connection.resources),
|
|
80
|
+
)
|
|
81
|
+
return { stopped, remoteFailure, events }
|
|
82
|
+
})
|
|
83
|
+
const forwardLogs = Effect.fnUntraced(function* <E extends ErrorSchema>(
|
|
86
84
|
contract: Contract<E>,
|
|
87
85
|
client: Client<E>,
|
|
88
86
|
connection: Connection["Service"],
|
|
89
|
-
)
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
yield* Effect.logWarning("Remote logs were dropped").pipe(
|
|
101
|
-
Effect.annotateLogs({
|
|
102
|
-
...(Option.isSome(connection.pid)
|
|
103
|
-
? { "remote.pid": connection.pid.value }
|
|
104
|
-
: {}),
|
|
105
|
-
"remote.logs.dropped": event.dropped - previous,
|
|
106
|
-
"remote.logs.droppedTotal": event.dropped,
|
|
107
|
-
}),
|
|
108
|
-
)
|
|
109
|
-
if (event._tag === "LogsEnded") {
|
|
110
|
-
yield* Deferred.succeed(logsEnded, undefined)
|
|
111
|
-
return
|
|
112
|
-
}
|
|
113
|
-
const entry = event.entry
|
|
114
|
-
const cause = yield* contract.decodeCause(entry.cause)
|
|
115
|
-
yield* Effect.logWithLevel(
|
|
116
|
-
entry.level === "All" || entry.level === "None"
|
|
117
|
-
? "Info"
|
|
118
|
-
: entry.level,
|
|
119
|
-
)(
|
|
120
|
-
...(Array.isArray(entry.message)
|
|
121
|
-
? entry.message
|
|
122
|
-
: [entry.message]),
|
|
123
|
-
cause,
|
|
124
|
-
).pipe(
|
|
87
|
+
) {
|
|
88
|
+
const logsEnded = yield* Deferred.make<void>()
|
|
89
|
+
const reportedDrops = yield* Ref.make(0)
|
|
90
|
+
yield* race(
|
|
91
|
+
connection,
|
|
92
|
+
client.Logs().pipe(
|
|
93
|
+
Stream.runForEach(
|
|
94
|
+
Effect.fnUntraced(function* (event) {
|
|
95
|
+
const previous = yield* Ref.getAndSet(reportedDrops, event.dropped)
|
|
96
|
+
if (event.dropped > previous)
|
|
97
|
+
yield* Effect.logWarning("Remote logs were dropped").pipe(
|
|
125
98
|
Effect.annotateLogs({
|
|
126
99
|
...(Option.isSome(connection.pid)
|
|
127
100
|
? { "remote.pid": connection.pid.value }
|
|
128
101
|
: {}),
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
: { "remote.threadId": connection.threadId }),
|
|
132
|
-
"remote.annotations": entry.annotations,
|
|
102
|
+
"remote.logs.dropped": event.dropped - previous,
|
|
103
|
+
"remote.logs.droppedTotal": event.dropped,
|
|
133
104
|
}),
|
|
134
105
|
)
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
106
|
+
if (event._tag === "LogsEnded") {
|
|
107
|
+
yield* Deferred.succeed(logsEnded, undefined)
|
|
108
|
+
return
|
|
109
|
+
}
|
|
110
|
+
const entry = event.entry
|
|
111
|
+
const cause = yield* contract.decodeCause(entry.cause)
|
|
112
|
+
yield* Effect.logWithLevel(
|
|
113
|
+
entry.level === "All" || entry.level === "None"
|
|
114
|
+
? "Info"
|
|
115
|
+
: entry.level,
|
|
116
|
+
)(
|
|
117
|
+
...(Array.isArray(entry.message) ? entry.message : [entry.message]),
|
|
118
|
+
cause,
|
|
119
|
+
).pipe(
|
|
120
|
+
Effect.annotateLogs({
|
|
121
|
+
...(Option.isSome(connection.pid)
|
|
122
|
+
? { "remote.pid": connection.pid.value }
|
|
123
|
+
: {}),
|
|
124
|
+
...(connection.threadId === undefined
|
|
125
|
+
? {}
|
|
126
|
+
: { "remote.threadId": connection.threadId }),
|
|
127
|
+
"remote.annotations": entry.annotations,
|
|
128
|
+
}),
|
|
129
|
+
)
|
|
130
|
+
}),
|
|
151
131
|
),
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
132
|
+
),
|
|
133
|
+
).pipe(
|
|
134
|
+
Effect.tapCause(connection.transport.report),
|
|
135
|
+
Effect.forkIn(connection.resources),
|
|
136
|
+
)
|
|
137
|
+
return logsEnded
|
|
138
|
+
})
|
|
139
|
+
export const initialize = Effect.fnUntraced(function* <E extends ErrorSchema>(
|
|
140
|
+
contract: Contract<E>,
|
|
141
|
+
) {
|
|
142
|
+
const connection = yield* Connection
|
|
143
|
+
const client = yield* RpcClient.make(contract.control).pipe(
|
|
144
|
+
Effect.provideService(
|
|
145
|
+
RpcClient.Protocol,
|
|
146
|
+
connection.transport.clientProtocol(Control.endpoint),
|
|
147
|
+
),
|
|
148
|
+
Scope.provide(connection.resources),
|
|
149
|
+
)
|
|
150
|
+
for (const service of contract.inject)
|
|
151
|
+
yield* service
|
|
152
|
+
.serve(connection.transport)
|
|
153
|
+
.pipe(
|
|
154
|
+
Effect.tapCause(connection.transport.report),
|
|
155
|
+
Effect.forkIn(connection.resources),
|
|
156
|
+
)
|
|
157
|
+
const events = yield* forwardEvents(contract, client, connection)
|
|
158
|
+
const logsEnded = yield* forwardLogs(contract, client, connection)
|
|
159
|
+
return { connection, client, ...events, logsEnded }
|
|
160
|
+
})
|
|
165
161
|
type Active<E extends ErrorSchema> = Effect.Success<
|
|
166
162
|
ReturnType<typeof initialize<E>>
|
|
167
163
|
>
|
|
@@ -179,9 +175,7 @@ export const load = <E extends ErrorSchema>(
|
|
|
179
175
|
(
|
|
180
176
|
cause,
|
|
181
177
|
): cause is Cause.Cause<
|
|
182
|
-
|
|
183
|
-
| ContractModule.UndeclaredFailure
|
|
184
|
-
| ContractModule.ChildFailure
|
|
178
|
+
E["Type"] | ContractModule.UndeclaredFailure | ChildFailure
|
|
185
179
|
> => Cause.isCause(cause),
|
|
186
180
|
Effect.failCause,
|
|
187
181
|
),
|
|
@@ -189,21 +183,20 @@ export const load = <E extends ErrorSchema>(
|
|
|
189
183
|
active.remoteFailure.await,
|
|
190
184
|
),
|
|
191
185
|
)
|
|
192
|
-
export const dispose = <E extends ErrorSchema>(
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
Deferred.await(active.
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
})
|
|
186
|
+
export const dispose = Effect.fnUntraced(function* <E extends ErrorSchema>(
|
|
187
|
+
active: Active<E>,
|
|
188
|
+
) {
|
|
189
|
+
const result = yield* race(
|
|
190
|
+
active.connection,
|
|
191
|
+
active.client.Dispose().pipe(Effect.catchIf(Cause.isCause, Effect.succeed)),
|
|
192
|
+
)
|
|
193
|
+
const cause = Cause.isCause(result) ? result : Cause.empty
|
|
194
|
+
// A remote cleanup failure still permits the bounded event and log tail to drain.
|
|
195
|
+
yield* race(
|
|
196
|
+
active.connection,
|
|
197
|
+
Deferred.await(active.stopped).pipe(
|
|
198
|
+
Effect.andThen(Deferred.await(active.logsEnded)),
|
|
199
|
+
),
|
|
200
|
+
).pipe(Effect.onError(() => Effect.failCause(cleanupCause(cause))))
|
|
201
|
+
return cause
|
|
202
|
+
})
|