@graftland/plugin-remote 0.3.1 → 0.3.3
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-Dr6sX7el.js → Bootstrap-H9gDsgsC.js} +2 -2
- package/dist/{Contract-DL2mHvaT.js → Contract-DsJtisvL.js} +2 -2
- package/dist/Contract.js +1 -1
- package/dist/{Errors-BMKmu5Y7.js → Errors-DYhsGZcZ.js} +3 -1
- package/dist/Errors.d.ts +7 -0
- package/dist/Errors.d.ts.map +1 -1
- package/dist/Errors.js +3 -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-CVyueNOf.js → Graft-B71CPA2Y.js} +20 -16
- package/dist/{Packages-JNL34JpS.js → Packages-AgoCGotL.js} +23 -26
- package/dist/{Peer-BT7eAGmh.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/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-An0HsIzl.js → childRuntime-Bm3iSg_N.js} +29 -26
- package/dist/{connectionEnded-DCpFCjMX.js → connectionEnded-BwcxQ7W8.js} +4 -4
- package/dist/{entry-B89sepMU.js → entry-psOpX3Bj.js} +72 -35
- package/dist/host/auth/bearer.d.ts +9 -1
- package/dist/host/auth/bearer.d.ts.map +1 -1
- package/dist/host/auth/bearer.js +1 -1
- package/dist/host/auth/jwt.d.ts +9 -1
- package/dist/host/auth/jwt.d.ts.map +1 -1
- package/dist/host/auth/jwt.js +1 -1
- package/dist/host/auth/mtls.d.ts +8 -1
- package/dist/host/auth/mtls.d.ts.map +1 -1
- package/dist/host/auth/mtls.js +2 -2
- package/dist/host/auth/none.d.ts +3 -1
- package/dist/host/auth/none.js +1 -1
- package/dist/host/command.d.ts +14 -1
- package/dist/host/command.d.ts.map +1 -1
- package/dist/host/command.js +4 -4
- package/dist/host/local.d.ts +2 -1
- package/dist/host/local.d.ts.map +1 -1
- package/dist/host/local.js +3 -3
- package/dist/host/unix.d.ts +6 -1
- package/dist/host/unix.d.ts.map +1 -1
- package/dist/host/unix.js +3 -3
- package/dist/host/websocket.d.ts +10 -1
- package/dist/host/websocket.d.ts.map +1 -1
- package/dist/host/websocket.js +3 -3
- package/dist/host/worker.d.ts +3 -1
- package/dist/host/worker.d.ts.map +1 -1
- package/dist/host/worker.js +4 -5
- package/dist/{importer-Bk6U_sn4.js → importer-Cvf88eAY.js} +5 -8
- package/dist/index.js +9 -9
- 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.d.ts +2 -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 +2 -1
- package/dist/internal/auth/tokenCredentials.d.ts.map +1 -1
- package/dist/internal/child.js +20 -17
- package/dist/internal/child.js.map +1 -1
- package/dist/internal/childRuntime.js +4 -4
- package/dist/internal/childRuntime.js.map +1 -1
- package/dist/internal/credentials.d.ts +1 -1
- package/dist/internal/directTransport.d.ts +1 -1
- package/dist/internal/entry.d.ts +415 -3
- package/dist/internal/entry.d.ts.map +1 -1
- package/dist/internal/entry.js +1 -1
- package/dist/internal/entry.js.map +1 -1
- package/dist/internal/execution.js +40 -5
- 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.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.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/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-DSVUY8Bq.js → port--3x2zJ4D.js} +8 -8
- package/dist/{release-BY4Mlluy.js → release-DfZPuIcK.js} +1 -1
- package/dist/runner/auth/bearer.d.ts +6 -1
- package/dist/runner/auth/bearer.d.ts.map +1 -1
- package/dist/runner/auth/bearer.js +2 -2
- package/dist/runner/auth/jwt.d.ts +29 -2
- package/dist/runner/auth/jwt.d.ts.map +1 -1
- package/dist/runner/auth/jwt.js +4 -4
- package/dist/runner/auth/jwt.js.map +1 -1
- package/dist/runner/auth/mtls.d.ts +6 -1
- package/dist/runner/auth/mtls.d.ts.map +1 -1
- package/dist/runner/auth/mtls.js +3 -3
- package/dist/runner/auth/none.d.ts +7 -1
- package/dist/runner/auth/none.js +1 -1
- package/dist/runner/index.d.ts +310 -1
- package/dist/runner/index.d.ts.map +1 -1
- package/dist/runner/index.js +5 -5
- package/dist/runner/stdio.d.ts +6 -1
- package/dist/runner/stdio.d.ts.map +1 -1
- package/dist/runner/stdio.js +3 -3
- package/dist/runner/unix.d.ts +6 -1
- package/dist/runner/unix.d.ts.map +1 -1
- package/dist/runner/unix.js +3 -3
- package/dist/runner/websocket.d.ts +24 -1
- package/dist/runner/websocket.d.ts.map +1 -1
- package/dist/runner/websocket.js +4 -4
- package/dist/{socketChannel-C_ppdSzz.js → socketChannel-CJvL2DiB.js} +2 -2
- package/dist/{supervisorPlugin-CivhM7x5.js → supervisorPlugin-t6Z6PrhD.js} +72 -76
- package/dist/{token-Cc_1CTbE.js → token-CYBNNlhS.js} +1 -1
- package/dist/{tokenCredentials-CI6mMRRd.js → tokenCredentials-CbCuk-Rt.js} +3 -3
- package/dist/{websocketServer-D2Hk7wsA.js → websocketServer-NQhODlEt.js} +5 -3
- package/dist/{workerChannel-cmLc13vm.js → workerChannel-C8hhBJzA.js} +1 -1
- package/package.json +4 -4
- package/src/Auth.ts +9 -2
- package/src/Errors.ts +8 -0
- package/src/Transport.ts +6 -2
- package/src/bin.ts +28 -30
- package/src/index.ts +5 -3
- 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/child.ts +248 -239
- package/src/internal/childRuntime.ts +81 -80
- package/src/internal/entry.ts +10 -11
- package/src/internal/execution.ts +69 -12
- package/src/internal/host/runner.ts +153 -153
- package/src/internal/host.ts +116 -120
- 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/watchdogMain.ts +16 -11
- package/src/internal/websocketServer.ts +18 -3
- package/src/runner/auth/jwt.ts +10 -6
- package/dist/cleanup-CXLa1Wd9.js +0 -13
package/src/internal/host.ts
CHANGED
|
@@ -46,121 +46,118 @@ const race = <A, E, R>(
|
|
|
46
46
|
effect: Effect.Effect<A, E, R>,
|
|
47
47
|
) => Effect.raceFirst(effect, connection.transport.failure)
|
|
48
48
|
|
|
49
|
-
const forwardEvents = <E extends ErrorSchema>(
|
|
49
|
+
const forwardEvents = Effect.fnUntraced(function* <E extends ErrorSchema>(
|
|
50
50
|
contract: Contract<E>,
|
|
51
51
|
client: Client<E>,
|
|
52
52
|
connection: Connection["Service"],
|
|
53
|
-
)
|
|
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
|
-
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>(
|
|
85
84
|
contract: Contract<E>,
|
|
86
85
|
client: Client<E>,
|
|
87
86
|
connection: Connection["Service"],
|
|
88
|
-
)
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
yield* Effect.logWarning("Remote logs were dropped").pipe(
|
|
100
|
-
Effect.annotateLogs({
|
|
101
|
-
...(Option.isSome(connection.pid)
|
|
102
|
-
? { "remote.pid": connection.pid.value }
|
|
103
|
-
: {}),
|
|
104
|
-
"remote.logs.dropped": event.dropped - previous,
|
|
105
|
-
"remote.logs.droppedTotal": event.dropped,
|
|
106
|
-
}),
|
|
107
|
-
)
|
|
108
|
-
if (event._tag === "LogsEnded") {
|
|
109
|
-
yield* Deferred.succeed(logsEnded, undefined)
|
|
110
|
-
return
|
|
111
|
-
}
|
|
112
|
-
const entry = event.entry
|
|
113
|
-
const cause = yield* contract.decodeCause(entry.cause)
|
|
114
|
-
yield* Effect.logWithLevel(
|
|
115
|
-
entry.level === "All" || entry.level === "None"
|
|
116
|
-
? "Info"
|
|
117
|
-
: entry.level,
|
|
118
|
-
)(
|
|
119
|
-
...(Array.isArray(entry.message)
|
|
120
|
-
? entry.message
|
|
121
|
-
: [entry.message]),
|
|
122
|
-
cause,
|
|
123
|
-
).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(
|
|
124
98
|
Effect.annotateLogs({
|
|
125
99
|
...(Option.isSome(connection.pid)
|
|
126
100
|
? { "remote.pid": connection.pid.value }
|
|
127
101
|
: {}),
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
: { "remote.threadId": connection.threadId }),
|
|
131
|
-
"remote.annotations": entry.annotations,
|
|
102
|
+
"remote.logs.dropped": event.dropped - previous,
|
|
103
|
+
"remote.logs.droppedTotal": event.dropped,
|
|
132
104
|
}),
|
|
133
105
|
)
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
+
}),
|
|
150
131
|
),
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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
|
+
})
|
|
164
161
|
type Active<E extends ErrorSchema> = Effect.Success<
|
|
165
162
|
ReturnType<typeof initialize<E>>
|
|
166
163
|
>
|
|
@@ -186,21 +183,20 @@ export const load = <E extends ErrorSchema>(
|
|
|
186
183
|
active.remoteFailure.await,
|
|
187
184
|
),
|
|
188
185
|
)
|
|
189
|
-
export const dispose = <E extends ErrorSchema>(
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
Deferred.await(active.
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
})
|
|
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
|
+
})
|
package/src/internal/port.ts
CHANGED
|
@@ -167,64 +167,66 @@ interface State {
|
|
|
167
167
|
readonly servers: HashMap.HashMap<string, ServerEndpoint>
|
|
168
168
|
readonly clients: HashMap.HashMap<string, ClientEndpoint>
|
|
169
169
|
}
|
|
170
|
-
const initialize = (
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
170
|
+
const initialize = Effect.fnUntraced(function* (
|
|
171
|
+
bytes: Channel,
|
|
172
|
+
options: Options,
|
|
173
|
+
): Effect.fn.Return<State, never, Scope.Scope> {
|
|
174
|
+
const limits = { ...defaults, ...options.limits }
|
|
175
|
+
const workers = yield* FailureGroup.make<TransportError>()
|
|
176
|
+
const incoming = yield* TxRef.make(
|
|
177
|
+
HashMap.empty<RequestKey, RequestState<RpcMessage.FromClientEncoded>>(),
|
|
178
|
+
)
|
|
179
|
+
const outgoing = yield* TxRef.make(
|
|
180
|
+
HashMap.empty<RequestKey, RequestState<RpcMessage.FromServerEncoded>>(),
|
|
181
|
+
)
|
|
182
|
+
const queues = {
|
|
183
|
+
control: yield* TxQueue.unbounded<Pending, Cause.Done>(),
|
|
184
|
+
data: yield* TxQueue.unbounded<Pending, Cause.Done>(),
|
|
185
|
+
log: yield* TxQueue.unbounded<Pending, Cause.Done>(),
|
|
186
|
+
}
|
|
187
|
+
const servers = yield* Effect.forEach(
|
|
188
|
+
Record.toEntries(options.serve),
|
|
189
|
+
Effect.fnUntraced(function* ([name, group]) {
|
|
190
|
+
return [
|
|
191
|
+
name,
|
|
192
|
+
{
|
|
193
|
+
group,
|
|
194
|
+
ready:
|
|
195
|
+
yield* Deferred.make<
|
|
196
|
+
Parameters<RpcServer.Protocol["Service"]["run"]>[0]
|
|
197
|
+
>(),
|
|
198
|
+
disconnects: yield* Queue.dropping<number>(1),
|
|
199
|
+
},
|
|
200
|
+
] satisfies readonly [string, unknown]
|
|
201
|
+
}),
|
|
202
|
+
).pipe(Effect.map(HashMap.fromIterable))
|
|
203
|
+
const clients = yield* Effect.forEach(
|
|
204
|
+
Record.toEntries(options.call),
|
|
205
|
+
Effect.fnUntraced(function* ([name, group]) {
|
|
206
|
+
return [
|
|
207
|
+
name,
|
|
208
|
+
{
|
|
209
|
+
group,
|
|
210
|
+
ready:
|
|
211
|
+
yield* Deferred.make<
|
|
212
|
+
Parameters<RpcClient.Protocol["Service"]["run"]>[1]
|
|
213
|
+
>(),
|
|
214
|
+
},
|
|
215
|
+
] satisfies readonly [string, unknown]
|
|
216
|
+
}),
|
|
217
|
+
).pipe(Effect.map(HashMap.fromIterable))
|
|
218
|
+
return {
|
|
219
|
+
bytes,
|
|
220
|
+
options,
|
|
221
|
+
limits,
|
|
222
|
+
workers,
|
|
223
|
+
incoming,
|
|
224
|
+
outgoing,
|
|
225
|
+
queues,
|
|
226
|
+
servers,
|
|
227
|
+
clients,
|
|
228
|
+
}
|
|
229
|
+
})
|
|
228
230
|
|
|
229
231
|
const admit = Effect.fnUntraced(function* <A>(
|
|
230
232
|
state: State,
|
|
@@ -447,41 +449,38 @@ const serverProtocol = (
|
|
|
447
449
|
),
|
|
448
450
|
})
|
|
449
451
|
}
|
|
450
|
-
const next = (state: State)
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
sent: true,
|
|
471
|
-
}),
|
|
472
|
-
)
|
|
473
|
-
}
|
|
474
|
-
return Option.some(frame)
|
|
475
|
-
}
|
|
476
|
-
if (
|
|
477
|
-
(yield* TxQueue.isDone(state.queues.control)) &&
|
|
478
|
-
(yield* TxQueue.isDone(state.queues.data)) &&
|
|
479
|
-
(yield* TxQueue.isDone(state.queues.log))
|
|
452
|
+
const next = Effect.fnUntraced(function* (state: State) {
|
|
453
|
+
yield* state.workers.check
|
|
454
|
+
for (const p of [
|
|
455
|
+
"control",
|
|
456
|
+
"data",
|
|
457
|
+
"log",
|
|
458
|
+
] satisfies ReadonlyArray<Priority>) {
|
|
459
|
+
const pending = yield* TxQueue.poll(state.queues[p])
|
|
460
|
+
if (Option.isNone(pending)) continue
|
|
461
|
+
const { frame, request } = pending.value
|
|
462
|
+
if (Option.isSome(request)) {
|
|
463
|
+
const table = yield* TxRef.get(state.outgoing)
|
|
464
|
+
const requestState = HashMap.get(table, request.value)
|
|
465
|
+
if (Option.isNone(requestState)) return Option.none<Frame>()
|
|
466
|
+
yield* TxRef.set(
|
|
467
|
+
state.outgoing,
|
|
468
|
+
HashMap.set(table, request.value, {
|
|
469
|
+
...requestState.value,
|
|
470
|
+
sent: true,
|
|
471
|
+
}),
|
|
480
472
|
)
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
473
|
+
}
|
|
474
|
+
return Option.some(frame)
|
|
475
|
+
}
|
|
476
|
+
if (
|
|
477
|
+
(yield* TxQueue.isDone(state.queues.control)) &&
|
|
478
|
+
(yield* TxQueue.isDone(state.queues.data)) &&
|
|
479
|
+
(yield* TxQueue.isDone(state.queues.log))
|
|
484
480
|
)
|
|
481
|
+
return yield* Cause.done()
|
|
482
|
+
return yield* Effect.txRetry
|
|
483
|
+
}, Effect.tx)
|
|
485
484
|
const writer = (state: State) =>
|
|
486
485
|
Stream.fromEffectRepeat(next(state)).pipe(
|
|
487
486
|
Stream.filterMap(Result.fromOption(() => undefined)),
|
|
@@ -592,18 +591,16 @@ export const make = Effect.fnUntraced(function* (
|
|
|
592
591
|
// The same failure remains observable through Port.await and client requests.
|
|
593
592
|
// This observer only publishes disconnects, even while the owner closes its scope.
|
|
594
593
|
yield* state.workers.await.pipe(
|
|
595
|
-
Effect.catchCause(
|
|
596
|
-
Effect.
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
TxRef.set(state.
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
}),
|
|
606
|
-
),
|
|
594
|
+
Effect.catchCause(
|
|
595
|
+
Effect.fnUntraced(function* () {
|
|
596
|
+
for (const server of HashMap.values(state.servers))
|
|
597
|
+
yield* Queue.offer(server.disconnects, 0)
|
|
598
|
+
yield* Effect.tx(
|
|
599
|
+
TxRef.set(state.incoming, HashMap.empty()).pipe(
|
|
600
|
+
Effect.andThen(TxRef.set(state.outgoing, HashMap.empty())),
|
|
601
|
+
),
|
|
602
|
+
)
|
|
603
|
+
}, Effect.uninterruptible),
|
|
607
604
|
),
|
|
608
605
|
Effect.forkScoped,
|
|
609
606
|
)
|
package/src/internal/release.ts
CHANGED
|
@@ -19,8 +19,9 @@ export const close = (
|
|
|
19
19
|
) =>
|
|
20
20
|
Effect.uninterruptible(
|
|
21
21
|
Scope.close(scope, exit).pipe(
|
|
22
|
-
Effect.catchCauseIf(
|
|
23
|
-
|
|
22
|
+
Effect.catchCauseIf(
|
|
23
|
+
Cause.hasInterruptsOnly,
|
|
24
|
+
Effect.fnUntraced(function* (cause) {
|
|
24
25
|
// Re-entering interruptibility observes pending external cancellation without producing a self-interrupt.
|
|
25
26
|
// Read it after release so cancellation arriving during a finalizer is included too.
|
|
26
27
|
const pending = yield* Effect.exit(Effect.interruptible(Effect.void))
|
|
@@ -112,73 +112,65 @@ const finish = (causes: ReadonlyArray<Cause.Cause<unknown>>) => {
|
|
|
112
112
|
/** Close partially acquired resources too; the normal release observes exit before stopping readers. */
|
|
113
113
|
const scopes = Effect.acquireRelease(
|
|
114
114
|
Effect.all({ resources: Scope.make(), process: Scope.make() }),
|
|
115
|
-
(scopes, exit)
|
|
116
|
-
Effect.
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
)
|
|
121
|
-
yield* finish([reason(process), reason(resources)])
|
|
122
|
-
}),
|
|
115
|
+
Effect.fnUntraced(function* (scopes, exit) {
|
|
116
|
+
const process = yield* Effect.exit(Release.close(scopes.process, exit))
|
|
117
|
+
const resources = yield* Effect.exit(Release.close(scopes.resources, exit))
|
|
118
|
+
yield* finish([reason(process), reason(resources)])
|
|
119
|
+
}),
|
|
123
120
|
)
|
|
124
121
|
|
|
125
122
|
/** Setup supplies a concrete control lifecycle; release never reads a later-installed effect. */
|
|
126
|
-
export const acquire = <A, E, R, D, DR>(
|
|
123
|
+
export const acquire = Effect.fnUntraced(function* <A, E, R, D, DR>(
|
|
127
124
|
target: Target,
|
|
128
125
|
contractModule: string,
|
|
129
126
|
options: Port.Options,
|
|
130
127
|
setup: Effect.Effect<A, E, R | Connection>,
|
|
131
128
|
dispose: (value: A) => Effect.Effect<Cause.Cause<unknown>, D, DR>,
|
|
132
129
|
timeout: Duration.Input,
|
|
133
|
-
)
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
owned.process,
|
|
152
|
-
)
|
|
153
|
-
}).pipe(Effect.interruptible),
|
|
154
|
-
(connection, exit) =>
|
|
155
|
-
Effect.gen(function* () {
|
|
156
|
-
const process = yield* Effect.exit(Release.close(owned.process, exit))
|
|
157
|
-
// Wait for exit while readers are alive; collect their final cause after resources close.
|
|
158
|
-
yield* connection.diagnostics
|
|
159
|
-
const resources = yield* Effect.exit(
|
|
160
|
-
Release.close(owned.resources, exit),
|
|
161
|
-
)
|
|
162
|
-
const diagnostics = yield* connection.diagnostics
|
|
163
|
-
yield* finish([reason(process), reason(resources), diagnostics])
|
|
164
|
-
}),
|
|
165
|
-
)
|
|
166
|
-
return yield* Effect.acquireRelease(
|
|
167
|
-
setup.pipe(Effect.provideService(Connection, connection)),
|
|
168
|
-
(value) =>
|
|
169
|
-
Effect.gen(function* () {
|
|
170
|
-
const graceful = yield* dispose(value).pipe(
|
|
171
|
-
Effect.interruptible,
|
|
172
|
-
Effect.timeout(timeout),
|
|
173
|
-
Effect.exit,
|
|
174
|
-
)
|
|
175
|
-
const terminated = yield* Effect.exit(
|
|
176
|
-
connection.terminate(Exit.isSuccess(graceful)),
|
|
130
|
+
) {
|
|
131
|
+
const owned = yield* scopes
|
|
132
|
+
const connection = yield* Effect.acquireRelease(
|
|
133
|
+
Effect.gen(function* () {
|
|
134
|
+
return target._tag === "Local" || target._tag === "Worker"
|
|
135
|
+
? yield* Local(
|
|
136
|
+
target,
|
|
137
|
+
contractModule,
|
|
138
|
+
options,
|
|
139
|
+
owned.resources,
|
|
140
|
+
owned.process,
|
|
141
|
+
).pipe(Effect.map(connected))
|
|
142
|
+
: yield* RunnerConnection.connect(
|
|
143
|
+
target,
|
|
144
|
+
contractModule,
|
|
145
|
+
options,
|
|
146
|
+
owned.resources,
|
|
147
|
+
owned.process,
|
|
177
148
|
)
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
149
|
+
}).pipe(Effect.interruptible),
|
|
150
|
+
Effect.fnUntraced(function* (connection, exit) {
|
|
151
|
+
const process = yield* Effect.exit(Release.close(owned.process, exit))
|
|
152
|
+
// Wait for exit while readers are alive; collect their final cause after resources close.
|
|
153
|
+
yield* connection.diagnostics
|
|
154
|
+
const resources = yield* Effect.exit(Release.close(owned.resources, exit))
|
|
155
|
+
const diagnostics = yield* connection.diagnostics
|
|
156
|
+
yield* finish([reason(process), reason(resources), diagnostics])
|
|
157
|
+
}),
|
|
158
|
+
)
|
|
159
|
+
return yield* Effect.acquireRelease(
|
|
160
|
+
setup.pipe(Effect.provideService(Connection, connection)),
|
|
161
|
+
Effect.fnUntraced(function* (value) {
|
|
162
|
+
const graceful = yield* dispose(value).pipe(
|
|
163
|
+
Effect.interruptible,
|
|
164
|
+
Effect.timeout(timeout),
|
|
165
|
+
Effect.exit,
|
|
166
|
+
)
|
|
167
|
+
const terminated = yield* Effect.exit(
|
|
168
|
+
connection.terminate(Exit.isSuccess(graceful)),
|
|
169
|
+
)
|
|
170
|
+
yield* finish([
|
|
171
|
+
Exit.isSuccess(graceful) ? graceful.value : graceful.cause,
|
|
172
|
+
reason(terminated),
|
|
173
|
+
])
|
|
174
|
+
}),
|
|
175
|
+
)
|
|
176
|
+
})
|