fix(agent/reconnectingpty): generate rpty id before starting lifecycle (#15475)

Fixes https://github.com/coder/coder/issues/12687

There was a race condition where we would start the rpty lifecycle
before generating the ID, leading to a data race where we would try to
concurrently read and write the struct field.
This commit is contained in:
Cian Johnston
2024-11-11 15:02:55 +00:00
committed by GitHub
parent bc9d875efe
commit b6e7498cb8
+2 -2
View File
@@ -67,8 +67,6 @@ func newScreen(ctx context.Context, cmd *pty.Cmd, options *Options, logger slog.
timeout: options.Timeout,
}
go rpty.lifecycle(ctx, logger)
// Socket paths are limited to around 100 characters on Linux and macOS which
// depending on the temporary directory can be a problem. To give more leeway
// use a short ID.
@@ -80,6 +78,8 @@ func newScreen(ctx context.Context, cmd *pty.Cmd, options *Options, logger slog.
}
rpty.id = hex.EncodeToString(buf)
go rpty.lifecycle(ctx, logger)
settings := []string{
// Disable the startup message that appears for five seconds.
"startup_message off",