Skip to content
This repository has been archived by the owner on Feb 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #210 from stealthrocket/fix-kill
Browse files Browse the repository at this point in the history
timecraft: fix gRPC teardown on Kill
  • Loading branch information
chriso authored Aug 10, 2023
2 parents 7c1c1bc + cff1241 commit b2a6e67
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions internal/timecraft/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,19 +320,6 @@ func (pm *ProcessManager) Start(moduleSpec ModuleSpec, logSpec *LogSpec, parentI
processID = uuid.New()
}

// Setup a gRPC server for the module so that it can interact with the
// timecraft runtime.
server := pm.serverFactory.NewServer(pm.ctx, processID, moduleSpec, logSpec)
serverListener, err := guest.Listen(pm.ctx, "tcp", fmt.Sprintf("127.0.0.1:%d", timecraftServicePort))
if err != nil {
return ProcessID{}, err
}
go func() {
if err := server.Serve(serverListener); err != nil && !errors.Is(err, net.ErrClosed) {
pm.cancel(fmt.Errorf("failed to serve gRPC server: %w", err))
}
}()

if moduleSpec.Trace != nil {
system = wasi.Trace(moduleSpec.Trace, system)
}
Expand Down Expand Up @@ -383,6 +370,21 @@ func (pm *ProcessManager) Start(moduleSpec ModuleSpec, logSpec *LogSpec, parentI
// TOOD: the sandbox should terminate on any host call to be more reliable.
group.Go(func() error { <-ctx.Done(); guest.Kill(); return nil })

// Setup a gRPC server for the module so that it can interact with the
// timecraft runtime.
server := pm.serverFactory.NewServer(pm.ctx, processID, moduleSpec, logSpec)
serverListener, err := guest.Listen(pm.ctx, "tcp", fmt.Sprintf("127.0.0.1:%d", timecraftServicePort))
if err != nil {
return ProcessID{}, err
}
go func() {
if err := server.Serve(serverListener); err != nil {
if ctx.Err() == nil && !errors.Is(err, net.ErrClosed) {
pm.cancel(fmt.Errorf("failed to serve gRPC server: %w", err))
}
}
}()

process := &ProcessInfo{
ID: processID,
ParentID: parentID,
Expand Down

0 comments on commit b2a6e67

Please sign in to comment.