From b6e7498cb861a711824a85ac0225cbe59d47f267 Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Mon, 11 Nov 2024 15:02:55 +0000 Subject: [PATCH] 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. --- agent/reconnectingpty/screen.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/agent/reconnectingpty/screen.go b/agent/reconnectingpty/screen.go index c6d56aa220..3fc93d8810 100644 --- a/agent/reconnectingpty/screen.go +++ b/agent/reconnectingpty/screen.go @@ -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",