-
Notifications
You must be signed in to change notification settings - Fork 894
refactor: change template archive extraction to be on provisioner #9264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
935719c
a29592a
1f0efb4
2be6cf0
39d6065
e39b8a2
d92608e
0412773
83deae6
d1a9b2a
8d7261f
ef1820f
96e1e64
2805dda
9762158
cf8a48b
3d7b6a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Signed-off-by: Spike Curtis <spike@coder.com>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,14 +36,23 @@ func (p *protoServer) Session(stream proto.DRPCProvisioner_SessionStream) error | |
} | ||
sessDir := fmt.Sprintf("Session%p", s) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why %p? isn't it better to link it with (PID+something/id)? if the process dies, it would be easier to find it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need something unique to the Session, for the lifetime of the Session. The pointer is a simple and easy choice. Each provisioner needs to be run with a unique work directory so that they don't trample on each others caches, so there is no need to qualify the pointer with a PID. The PID might make things easier to find... if you know the PID, which is rarely the case after you have a crash. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Point in favour of PID: the PID will at least show up in dmesg in case of an OOMKill. |
||
s.WorkDirectory = filepath.Join(p.opts.WorkDirectory, sessDir) | ||
err := os.MkdirAll(s.WorkDirectory, 0o700) | ||
// the WorkDirectory shouldn't exist, but it's possible it does from a restarted process or failed cleanup | ||
err := os.RemoveAll(s.WorkDirectory) | ||
if err != nil { | ||
// RemoveAll returns nil if (as expected) the path doesn't exist. So, if we hit an error, the WorkDirectory | ||
// exists AND we failed to clean it up. | ||
s.Logger.Error(s.Context(), "failed to pre-clean work directory", slog.Error(err)) | ||
return xerrors.Errorf("failed to pre-clean work directory: %w", err) | ||
} | ||
err = os.MkdirAll(s.WorkDirectory, 0o700) | ||
if err != nil { | ||
return xerrors.Errorf("create work directory %q: %w", s.WorkDirectory, err) | ||
} | ||
defer func() { | ||
var err error | ||
// Cleanup the work directory after execution. | ||
for attempt := 0; attempt < 5; attempt++ { | ||
err := os.RemoveAll(s.WorkDirectory) | ||
err = os.RemoveAll(s.WorkDirectory) | ||
if err != nil { | ||
// On Windows, open files cannot be removed. | ||
// When the provisioner daemon is shutting down, | ||
|
@@ -54,8 +63,10 @@ func (p *protoServer) Session(stream proto.DRPCProvisioner_SessionStream) error | |
continue | ||
} | ||
s.Logger.Debug(s.Context(), "cleaned up work directory") | ||
break | ||
return | ||
} | ||
s.Logger.Error(s.Context(), "failed to clean up work directory after multiple attempts", | ||
slog.F("path", s.WorkDirectory), slog.Error(err)) | ||
}() | ||
req, err := stream.Recv() | ||
if err != nil { | ||
|
@@ -70,7 +81,7 @@ func (p *protoServer) Session(stream proto.DRPCProvisioner_SessionStream) error | |
s.logLevel = proto.LogLevel_value[strings.ToUpper(s.Config.ProvisionerLogLevel)] | ||
} | ||
|
||
err = s.ExtractArchive() | ||
err = s.extractArchive() | ||
if err != nil { | ||
return xerrors.Errorf("extract archive: %w", err) | ||
} | ||
|
@@ -176,7 +187,7 @@ func (s *Session) Context() context.Context { | |
return s.stream.Context() | ||
} | ||
|
||
func (s *Session) ExtractArchive() error { | ||
func (s *Session) extractArchive() error { | ||
ctx := s.Context() | ||
|
||
s.Logger.Info(ctx, "unpacking template source archive", | ||
|
Uh oh!
There was an error while loading. Please reload this page.