diff --git a/coderd/provisionerjobs.go b/coderd/provisionerjobs.go index f667c2ec65d72..99fb647385f5e 100644 --- a/coderd/provisionerjobs.go +++ b/coderd/provisionerjobs.go @@ -318,6 +318,10 @@ func (f *logFollower) follow() { return } defer subCancel() + // Move cancel up the stack so it happens before unsubscribing, + // otherwise we can end up in a deadlock due to how the + // in-memory pubsub does mutex locking on send/unsubscribe. + defer cancel() // we were provided `complete` prior to starting this subscription, so // we also need to check whether the job is now complete, in case the