guan404ming commented on code in PR #70085:
URL: https://github.com/apache/airflow/pull/70085#discussion_r3638043481
##########
ts-sdk/src/coordinator/log-channel.ts:
##########
@@ -66,22 +67,39 @@ export class LogChannel {
this.isRoot = isRoot;
}
+ /** Create a root channel with no socket yet; records are buffered
+ * until {@link LogChannel#connect} flushes them. */
+ static createBuffered(name: string = DEFAULT_LOGGER_NAME): LogChannel {
+ return new LogChannel({ sock: null, connected: false, closed: false,
buffer: [] }, name, true);
+ }
+
static async connect(addr: string, name: string = DEFAULT_LOGGER_NAME):
Promise<LogChannel> {
- const shared: LogChannelState = {
- sock: await connectTcp(addr),
- connected: true,
- closed: false,
- };
- shared.sock.on("error", (err) => {
+ const channel = LogChannel.createBuffered(name);
+ await channel.connect(addr);
+ return channel;
+ }
+
+ /** Connect the socket and flush buffered records, in order. Root only. */
+ async connect(addr: string): Promise<void> {
+ if (!this.isRoot) return;
+ const shared = this.shared;
+ const name = this.name;
+ const sock = await connectTcp(addr);
+ shared.sock = sock;
+ shared.connected = true;
Review Comment:
Good catch, agreed on both. Added the guards. Skipped only the
`shared.closed` race branch: `close()` runs in `runtime.ts`'s `finally`, after
`connect()` settles, so it can't land mid-dial.
--
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]